0

Please help me. I'm a beginner in Python. I have an Excel file which contains the following rows:

[[12, 11.17], [8, 29.62], [14, 18.74]]
[[2, 10.98], [16, 113.72]]
....etc

Each row contains different quantities of values. I need to create DataFrame which will look like

A  | B
12 |11.17
8  |29.62
14 |18.74
2  |10.98 
...

Column A contains left integer number in bracket, Column B contains number after comma.

I try to save each row from Excel file to variables, for example:

z1=[[12, 11.17], [8, 29.62], [14, 18.74]]
z2=[[2, 10.98], [16, 113.72]]

and then do:

zf1 = pd.DataFrame(z1)
zf2 = pd.DataFrame(z2)
frames = [zf1, zf2]
res = pd.concat(frames)

But I have more 100 rows! What should I do to create dataframe with two columns from this file? Thanks.

  • It's hard to tell precisely from your description, but it sounds like you want a combination of `explode` to get the initial rows into multiple rows, then [this answer](https://stackoverflow.com/questions/35491274/pandas-split-column-of-lists-into-multiple-columns) to separate the indivisual sublists into columns. We could be better help if you showed a sample of your dataframe that you get from just `read_excel` according to: [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – G. Anderson Mar 06 '20 at 20:14
  • i would do it in noteped++, copy the lists from excel, replace all ], [ with \n then replace all [ with "" and replace all ] with "", this will give you the table shape you want, then upload it to pandas – trigonom Mar 08 '20 at 21:33

0 Answers0