How to split a DataFrame on each different value in a column?

前端 未结 3 1019
萌比男神i
萌比男神i 2021-01-23 10:16

Below is an example DataFrame.

      0      1     2     3          4
0   0.0  13.00  4.50  30.0   0.0,13.0
1   0.0  13.00  4.75  30.0   0.0,13.0
2   0.0  13.00           


        
3条回答
  •  别那么骄傲
    2021-01-23 11:08

    I will use GroupBy.__iter__:

    d = dict(df.groupby(df['0'].diff().ne(0).cumsum()).__iter__())
    #d = dict(df.groupby(df[0].diff().ne(0).cumsum()).__iter__())
    

    Note that if there are repeated non-consecutive values ​​different groups will be created, if you only use groupby(0) they will be grouped in the same group

提交回复
热议问题