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
  • 770
  • 3
  • 11
  • 23

1 Answers1

1

Use str.split with expand=True:

print(df['Values'].str.split(',', expand=True))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114