I have a really simple Pandas dataframe where each cell contains a list. I would like to break each list item into its own column. I can do this by exporting the values ββand then creating a new dataframe . This does not seem to be a good way to do this, especially if my dataframe had a column away from the list column.
import pandas as pd df = pd.DataFrame(data=[[[8,10,12]], [[7,9,11]]]) df = pd.DataFrame(data=[x[0] for x in df.values])
Required Conclusion:
0 1 2 0 8 10 12 1 7 9 11
Follow-up based on @Psidom answer:
If I had a second column:
df = pd.DataFrame(data=[[[8,10,12], 'A'], [[7,9,11], 'B']])
How not to lose another column?
Required Conclusion:
0 1 2 3 0 8 10 12 A 1 7 9 11 B
source share