python - 使用pandas获取按天的数据累计和

标签 python pandas dataframe wunderground

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()

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

关于python - 使用pandas获取按天的数据累计和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36389017/

相关文章:

Pandas 为缺少的日期填零 * 由 * 组定义

python - pandas如何对一段时间进行分组,然后在组内过滤后返回一个df?

python - 如何从 Shell 脚本获取循环变量以在 python 脚本中检索

python - π 的莱布尼茨公式 - 这有什么用吗? (Python)

python - Pandas:根据条件求和字符串

python - 获取数据帧中每行中的前 n 个值及其出现的列名称

python - Pandas DataFrame 操作和转换

python - 使用 Python pandas 检查列是否包含相同的值或 NaN

python - 在释放锁之前如何确保 PostgreSQL 中的写入已完成?

python - 如何动态地将谓词传递给过滤函数?