Split pandas dataframe into multiple dataframes with equal numbers of rows

后端 未结 2 1353
予麋鹿
予麋鹿 2021-01-13 07:32

I have a dataframe df :

        a              b          c
0   0.897134    -0.356157   -0.396212
1   -2.357861   2.066570    -0.512687
2   -0.0         


        
2条回答
  •  囚心锁ツ
    2021-01-13 08:01

    There are many ways to do what you want, your method looks over-complicated. A groupby using a scaled index as the grouping key would work:

    df = pd.DataFrame(data=np.random.rand(100, 3), columns=list('ABC'))
    groups = df.groupby(np.arange(len(df.index))/10)
    for (frameno, frame) in groups:
        frame.to_csv("%s.csv" % frameno)
    

提交回复
热议问题