def insert(df):
level_0 = df.index.values[0][0] # 取得第一列索引名
diff = df.loc[(level_0, '2020-06-02'), 'new_cases'] - df.loc[(level_0, '2020-06-01'), 'new_cases'] # 计算差值
df.loc[(level_0, 'diff'), 'new_cases'] = diff # 插入值
return df
data.groupby('location').apply(insert).droplevel(0)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…