我想计算每个月(即每个创建的组)的VWAP值。
data['Month'] = pd.DatetimeIndex(data['Date']).month
data.head()
data['Year'] = pd.DatetimeIndex(data['Date']).year
data.head()
group = data.groupby(['Month', 'Year'])
group.first()
data['VWAP'] = (np.cumsum(data['Close Price' * data['Total Traded
Quantity']) / np.cumsum(data['Total Traded Quantity']))
AttributeError:“ DataFrame”对象没有属性“ quantity”
答案 0 :(得分:1)
您忘了在数据['收盘价']之后写']',这是我的代码
df['Month'] = pd.DatetimeIndex(df['Date']).month
df['Year'] = pd.DatetimeIndex(df['Date']).year
group = df.groupby(['Month', 'Year'])
df['VWAP'] = (np.cumsum(df['Close Price'] * df['Total Traded Quantity']) / np.cumsum(df['Total Traded Quantity']))
谢谢...