Thiebout
Thiebout

Reputation: 171

Pandas split column of (unequal length) list into multiple columns

A slight variant to this question: Pandas split column of lists into multiple columns

Given a dataframe:

col1
[0, 1, 2]
[0, 1]
[0, 1, 2, 3, 4, 5, 6]
[0, 1, 2, 3]

How can I convert this into a dataframe with columns equal to the maximum length?

col1 col2 col3 col4 col5 col6 col7
0    1    2 
0    1 
0    1    2    3    4    5    6
0    1    2    3 

Upvotes: 3

Views: 1817

Answers (1)

BENY
BENY

Reputation: 323316

Using pandas DataFrame re-create you df

pd.DataFrame(df.col1.values.tolist())

Upvotes: 3

Related Questions