在Python中将年度累计数据转换为月度绝对值 - 问答 - Python中文网
df[['cum_v1', 'cum_v2']] = df.groupby(df['date'].str[:4]).diff(-1).fillna(df[['v1', 'v2']])
print(df)
在Python中将年度累计数据转换为月度绝对值 - 问答 - Python中文网
df[['cum_v1', 'cum_v2']] = df.groupby(df['date'].str[:4]).diff(-1).fillna(df[['v1', 'v2']])
print(df)