Convert daily data in pandas dataframe to monthly data

后端 未结 1 1484
你的背包
你的背包 2021-01-16 06:31

My dataframe has daily stock data in it:

       Date       AAPL      NFLX       INTC  
0 2008-01-02  27.834286  3.764286  25.350000    
1 2008-01-03  27.8471         


        
1条回答
  •  悲&欢浪女
    2021-01-16 06:52

    Your index is not a DatetimeIndex. But you can make it a DatetimeIndex:

    df.set_index('Date', inplace=True)
    df.index = pd.to_datetime(df.index)
    df.resample('1M').mean()
    #                 AAPL      NFLX    INTC
    #Date                                   
    #2008-01-31  26.248857  3.577429  23.566
    

    0 讨论(0)
提交回复
热议问题