python按时间分类数据,Python会按年份+月份分割数据表列表

本文介绍了如何使用Python将CSV文件中的数据按年月及类别进行分组。通过示例展示了如何将日期转换为年月格式,并使用NumPy对数据进行操作,实现按年月和类别分组,以便于后续的数据分析和绘图。
摘要由CSDN通过智能技术生成

I have the following csv files:

# simulate a csv file

from StringIO import StringIO

data = StringIO("""

2012-04-01,00:10, A, 10

2012-04-01,00:20, B, 11

2012-04-01,00:30, B, 12

2012-04-02,00:10, A, 18

2012-05-02,00:20, A, 14

2012-05-02,00:30, B, 11

2012-05-03,00:10, A, 10

2012-06-03,00:20, B, 13

2012-06-03,00:30, C, 12

""".strip())

which I would like to gropu by year+month plus category (ie. A, B, C).

I would like the final data to have grouping by month and then by category

as a view of the original data

2012-04, A

>> array[0,] => 2012-04-01,00:10, A, 10

>> array[3,] => 2012-04-02,00:10, A, 18

2012-04, B

>> array[1,] => 2012-04-01,00:20, B, 11

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值