将值减去熊猫中的组

时间:2020-03-25 17:53:35

标签: python-3.x pandas pandas-groupby

我有以下DataFrame:

df = pd.DataFrame()
df['I'] = [-1.922410e-11, -6.415227e-12,  1.347632e-11,  1.728460e-11,3.787953e-11]
df['V'] = [0,0,0,1,1]
off = df.groupby('V')['I'].mean() 

我需要将off值减去相应的df['I']值。在代码中,我想要这样的东西:

for i in df['V'].unique():
    df['I'][df['V']==i] -= off.loc[i]

我想知道是否还有另一种不使用循环的方法。

0 个答案:

没有答案
相关问题