How do I Pass a List of Series to a Pandas DataFrame?

后端 未结 6 1999
栀梦
栀梦 2021-02-03 23:57

I realize Dataframe takes a map of {\'series_name\':Series(data, index)}. However, it automatically sorts that map even if the map is an OrderedDict().

Is there a simpl

6条回答
  •  太阳男子
    2021-02-04 00:52

    Simply passing the list of Series to DataFrame then transposing seems to work too. It will also fill in any indices that are missing from one or the other Series.

    import pandas as pd
    from pandas.util.testing import rands
    data = [pd.Series([rands(4) for j in range(6)],
                      index=pd.date_range('1/1/2000', periods=6),
                      name='col'+str(i)) for i in range(4)]
    df = pd.DataFrame(data).T
    print(df)
    

提交回复
热议问题