converting daily stock data to weekly-based via pandas in Python

后端 未结 4 900
栀梦
栀梦 2020-12-23 10:48

I\'ve got a DataFrame storing daily-based data which is as below:

Date              Open        High         Low       Close   Volume
2010-01-04         


        
4条回答
  •  渐次进展
    2020-12-23 11:35

    Not a direct answer, but suppose the columns are the dates (transpose of your table), without missing dates.

    '''sum up daily results in df to weekly results in wdf'''
    wdf = pd.DataFrame(index = df.index)
    for i in range(len(df.columns)):
        if (i!=0) & (i%7==0):
            wdf['week'+str(i//7)]= df[df.columns[i-7:i]].sum(axis = 1)
    

提交回复
热议问题