0

I have a pandas dataframe, where the table contents look something like this:

             var1         var2
0               9  [1.0, 2.0, 3.0 ,4.0]
1              10  [1.0, 0.0, 4.0, 2.0]
...(other rows)

So, the var2 coloumn contains arrays (of the same size for each row, in this example, with a length of 4, and the arrays contain floats). What I would like to do, is get rid of the arrays, and introduce their elements as new coloumns to the dataframe. So aiming for:

             var1      newvar0   newvar1   newvar2   newvar3
0               9          1.0       2.0       3.0       4.0
1              10          1.0       0.0       4.0       2.0
...

I guess I could do this the brute-force way of copying the contents to temporary variables, adding the new coloumns one by one from iterating over the temporary variables, and then dropping the var2 coloumn. But is there perhaps a "more pythonic", or simply just more concise way of doing this transformation? (The actual dataframe is larger with longer arrays).

Thanks a lot!

WhiteWolf
  • 25
  • 6

0 Answers0