Convert pandas series of lists to dataframe

前端 未结 7 1603
执笔经年
执笔经年 2020-12-14 04:16

I have a series made of lists

import pandas as pd
s = pd.Series([[1, 2, 3], [4, 5, 6]])

and I want a DataFrame with each column a list.

7条回答
  •  攒了一身酷
    2020-12-14 04:39

    pd.DataFrame.from_records should also work using itertools.zip_longest:

    from itertools import zip_longest
    
    pd.DataFrame.from_records(zip_longest(*s.values))
    
    #    0  1
    # 0  1  4
    # 1  2  5
    # 2  3  6
    

提交回复
热议问题