1

I have a dataframe:

               Values   
                1,2
                nan,7,8
                4
                9,1

How can I split this column so that each value is now in its own column?

               col1       col2     col3 
                1         2
                nan       7          8
                4
                9         1

The only answers I have found are about splitting a column into two columns. How to split a column into two columns?

Mazz
  • 700
  • 2
  • 10
  • 22

1 Answers1

1

Use str.split with expand=True:

print(df['Values'].str.split(',', expand=True))
U12-Forward
  • 65,118
  • 12
  • 70
  • 89