我有一个数据框如下 日期,Qname,aht,x,y,z
我想在按当前日期偏移的30天滚动窗口中计算按数据和名称分组的aht的平均值。
from pandas.tseries.offsets import BDay
business_day = BDay().onOffset
df['gmt_dt'] = pd.to_datetime(df.Int_Date)
business_days = df.gmt_dt.map(business_day)
business_df = df[business_days]
business_df.set_index(['date','Qname'])
df['AVG_AHT'] = business_df.reset_index(level='name').groupby(['Qname']) ['AHT'].shift().rolling("30D", min_periods=1).mean()
给出了错误KeyError:
Q级名称必须与名称相同(无)