pandas 季度,使用python和pandas按季度分组数据

本文讲述了如何使用Pandas和Python处理CSV文件,根据月份将数据分组到四季,并计算每个季节的平均值。示例代码展示了如何创建一个字典映射月份到季节,然后应用到数据框中,最后进行分组和计算。
摘要由CSDN通过智能技术生成

I want to use Pandas and Python to iterate through my .csv file and group the data by seasons calculating the mean for each season in the year. Currently the quarterly script does Jan-Mar, Apr-Jun etc. I want the seasons correlate to months by - 11: 'Winter', 12: 'Winter', 1: 'Winter', 2: 'Spring', 3: 'Spring', 4: 'Spring', 5: 'Summer', 6: 'Summer', 7: 'Summer', \

8: 'Autumn', 9: 'Autumn', 10: 'Autumn'

I have the following data:

Date,HAD

01/01/1951,1

02/01/1951,-0.13161201

03/01/1951,-0.271796132

04/01/1951,-0.258977158

05/01/1951,-0.198823057

06/01/1951,0.167794502

07/01/1951,0.046093808

08/01/1951,-0.122396694

09/01/1951,-0.121824587

10/01/1951,-0.013002463

This is my code so far:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值