0

i have a series that i need it in Dataframe. so the series looks like this.

column1              [-333, -333, -3,3 -33, -33, ...
column2              [-121.0, -431.0, -41.0, -1.0, -1.0, ...
column3              [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, ...
column4              [-451.0, -5121.0, -41.0, -21.0, -4121.0, ...
column5              [1451.0, 19851.0, 1451.0, 1451.0, 1941.0, ...  

i tried to implement this post (pandas-series-to-dataframe-using-series-indexes-as-columns) but i got this dataframe (i'm illustrating only for one column here) which all the value in a list is in one row of the dataframe:

     column1    

0    [-9.0, 
     -811.0, 
     -71.0, 
     -691.0, 
     -41.0, ...

is there any way to convert pandas series into dataframe while the value is a list and column value is the index.

EDIT:

the data as srs.head().to_dict()

{'column1': masked_array(data=[-4524, -41144, -44314,...,444,44005,  44],
Mostafa Bouzari
  • 9,207
  • 3
  • 16
  • 26

1 Answers1

1

Use explode:

df = pd.DataFrame(srs).T.explode(list(srs.index))
not_speshal
  • 22,093
  • 2
  • 15
  • 30