使用pandas按天获取累积数据总和

Python

我从Wunderground获得了122天的天气数据,没有相等的采样间隔时间.这是我的数据样本:

Bangor Weather Data from Wunderground
Datetime,Temp(F),Precip(in.),Snow (in.),PET(in./day),Baro(mBar)
    2015-12-02 01:30:00,1.1,0.3,0.0,0.45524647117649564,1017.5 
    2015-12-02 01:53:00,1.1,0.3,0.0,0.45524647117649564,1017.6 
    2015-12-02 02:20:00,1.1,0.3,0.0,0.45524647117649564,1017.2 
    2015-12-02 02:53:00,1.7,0.5,0.0,0.500024812603692,1016.7 
    2015-12-02 02:55:00,1.7,0.3,0.0,0.500024812603692,1016.5 
    2015-12-02 03:09:00,1.1,0.3,0.0,0.45524647117649564,1016.1 
    2015-12-02 03:33:00,1.1,0.5,0.0,0.45524647117649564,1016.1 
    2015-12-02 03:53:00,1.7,0.8,0.0,0.500024812603692,1016.1 
    2015-12-02 04:34:00,1.7,0.5,0.0,0.500024812603692,1015.1 
    2015-12-02 04:46:00,1.7,0.5,0.0,0.500024812603692,1015.1 
    2015-12-02 04:53:00,1.7,0.8,0.0,0.500024812603692,1015.1 
    2015-12-02 05:13:00,1.7,0.0,0.0,0.500024812603692,1014.4 

我希望得到整个数据集的每日积雪(重新设置为零,为新的一天).我希望我的输出看起来像:

    2015-12-01,0.0
    2015-12-02,0.0
    2015-12-03,1.0
    2015-12-04,3.0
    2015-12-05,0.0
    2015-12-06,1.0

我怎么用pandas来做这个?

最佳答案 那是你要的吗?

df.groupby(df.Datetime.dt.date)['Snow (in.)'].sum()

这将为您提供每天的雪量(总和)

点赞