Splitting dataframe into multiple dataframes

后端 未结 11 1098
南方客
南方客 2020-11-22 01:16

I have a very large dataframe (around 1 million rows) with data from an experiment (60 respondents).

I would like to split the dataframe into 60 dataframes (a datafra

11条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 01:33

    In addition to Gusev Slava's answer, you might want to use groupby's groups:

    {key: df.loc[value] for key, value in df.groupby("name").groups.items()}
    

    This will yield a dictionary with the keys you have grouped by, pointing to the corresponding partitions. The advantage is that the keys are maintained and don't vanish in the list index.

提交回复
热议问题