我正在从Quandl获取股票数据。我有每天的交易量,我想找到每周的交易量。
import pandas as pd
import datetime as dt
from pandas_datareader import data, wb
start = dt.datetime(2015, 1, 1)
end = dt.datetime.today()
stocks = ["WIKI/AAPL", "WIKI/TSLA", "WIKI/IBM", "WIKI/LNKD"]
key = ...
df = data.DataReader(stocks, "quandl", start, end, api_key=key)
vol = df['Volume']
# now I want to Aggregate the data of Volume to weekly, I tried this but it doesn't work:
vol['week'] = vol.index.week
vol['year'] = vol.index.year
week = vol.groupby(['week','year']).sum()
week.head()
print(df.head())
答案 0 :(得分:0)
更像这样。
df_week = df.groupby(['week','year'])["Volume"].sum()