python 读取csv文件中某一段月份中的数据?
迷茫
迷茫 2017-04-18 10:16:45
0
2
1001

这是问题:Find out how much time and over how many separate days did R.Lennon work on administering the Jira Server between August and September.

csv里是这样的

我才开始学习timeseries部分,大概逻辑有了,但是不知道怎么用代码表达。请大神帮忙提一点建议,谢谢!

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
刘奇

Split Date field using re.split

import csv,re

with open('xxx.csv','rb') as rf:
    reader = csv.reader(rf)
    with open('xxx_new.csv','wb') as wf:
        writer = csv.writer(wf)
        headers = reader.next()
        writer.writerow(headers)
        for row in reader:
            t = re.split('\W+',row[1])  
            # row[1]为Date字段,被拆为['1', '11', '2016', '14', '17']
            if int(t[1]) == 11:  # 假设你想要11月数据
                writer.writerow(row)
阿神

You said timeseries, did you use pandas?
If it’s pandas, it’s actually quite simple. Assume that the name of datefrmae is df
First make sure that the Date column is converted to DatetimeIndex. This can be done with df['newdate']=pd.DatetimeIndex(df['date'])
Then filter df[df['newdate' ].dt.month==9] can filter out all September data,

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template