0

I have following pandas series

0    [1, 11283, 1, 5]
1        [2, 5, 1, 1]
2      [6, 33, 21, 2]
3    [11283, 1, 5, 1]
4     [8430, 1, 2, 2]
5        [2, 1, 1, 1]

I need to right this to csv. But I need each item in a list as separate column. For example: In fist row, 1, 11283, 1, 5 should be separate column

0

1 Answer 1

2

Assuming your series is called s, you may create a new DataFrame using tolist:

out = pd.DataFrame(s.values.tolist())

       0      1   2  3
0      1  11283   1  5
1      2      5   1  1
2      6     33  21  2
3  11283      1   5  1
4   8430      1   2  2
5      2      1   1  1

And save to csv.

pd.to_csv(out)
Sign up to request clarification or add additional context in comments.

1 Comment

@user2805885 added an explanation

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.