Partition pandas .diff() in multi-index level

后端 未结 1 1334
臣服心动
臣服心动 2020-12-20 15:49

My question relates to calling .diff() within the partition of a multi index level

In the following sample the output of the first

df.diff() is

<         


        
相关标签:
1条回答
  • 2020-12-20 16:22

    Just groupby by level=0 or 'Greek' if you prefer and then you can call diff on values:

    In [179]:
    
    df.groupby(level=0)['values'].diff()
    Out[179]:
    Greek  English
    alpha  a         NaN
           b           2
           c           2
           d           2
    beta   e         NaN
           f           1
           g           1
           h           1
    dtype: float64
    
    0 讨论(0)
提交回复
热议问题