0

tried searching Stack OF and Google for similar issues but couldn't solve my specific problem.

I have a pandas dataframe that looks like the following:

                                                    0
0   [28.1006, 3.0517, 0.001, 25.592674, 28.1006, 1...
1   [27.7047, 3.41844, 0.134, 25.592755, 27.7047, ...
2   [27.6291, 3.9317, 0.258, 25.592836, 27.629, 23...
3   [27.2119, 4.08375, 0.199, 25.592917, 27.2119, ...
4   [26.8867, 4.73379, 0.498, 25.592998, 26.8866, ...
5   [26.6336, 4.996, 0.697, 25.593079, 26.6334, 31...
6   [26.6366, 5.12371, 0.827, 25.59316, 26.6364, 3...
7   [26.5085, 5.1808, 1.217, 25.593241, 26.5082, 3...
8   [26.4885, 5.2233, 1.339, 25.593322, 26.4882, 3...
9   [26.434, 5.23135, 1.578, 25.593403, 26.4336, 3...
10  [26.4189, 5.24276, 1.875, 25.593484, 26.4185, ...

Where each row was generated from a list. As observed, I have multiple rows but only a single column. I want to convert my dataframe to multiple columns for each comma-separated value.

Also, I'd like to add a header so I can name each column.

Any thoughts?

I'm only starting at programming, so thanks in advance.

  • where did the data come from and how did you convert it to a pd.DataFrame? – Jeff Tilton Apr 30 '17 at 15:15
  • Either `df[0].apply(pd.Series)` or `pd.DataFrame(df[0].tolist())`. – ayhan Apr 30 '17 at 15:17
  • @JeffTilton it was in a dictionary. each element of the dictionary is a list of lists. I used: `df_st2 = pd.DataFrame(d['st2'])` to convert it to a dataframe, where 'st2' is a list of lists. I plan to do a dataframe for each element of the dictionary. – Vini Salazar Apr 30 '17 at 15:43
  • @ayhan this worked, so simple, thank you very much :) – Vini Salazar Apr 30 '17 at 15:46

0 Answers0