Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas dataframe from series of series

Tags:

python

pandas

I have a pandas series of series, like so:

series_list = [pd.Series([1,2], index = ['A', 'B']), pd.Series([3,4], index = ['A', 'B'])]
data = pd.Series(series_list, index = ['i', 'ii'])

I would like to turn this data into a dataframe, using one index as the dataframe's column index, the other as the row index:

pd.DataFrame({'A': [1,3], 'B': [2,4]}, index = ['i', 'ii'])

What is the best way to do this?

like image 364
Anne Avatar asked Jan 19 '26 02:01

Anne


1 Answers

Strict approach works fine:

pd.DataFrame(series_list,index = ['i', 'ii'])
like image 76
hvedrung Avatar answered Jan 21 '26 16:01

hvedrung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!