搜尋
問答 python 读取csv文件中某一段月份中的数据?

0

这是问题: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部分,大概逻辑有了,但是不知道怎么用代码表达。请大神帮忙提一点建议,谢谢!

Your Answer
提交

2 個答案
0

使用re.split拆分Date欄位

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)
2017-04-18 10:18:45

提交

0

你說timeseries,是用pandas麼?
如果是pandas,其實還蠻簡單的。假設datefrmae的名字是df
首先確保Date那列轉換為DatetimeIndex,這個可以用df['newdate']=pd.DatetimeIndex(df['date'])完成
然後就是篩選了df[df['newdate' ].dt.month==9]就能篩選出所有9月的資料了,

2017-04-18 10:18:45

提交

Hot Tools

vc9-vc14(32+64位元)運行庫合集(連結在下方)

vc9-vc14(32+64位元)運行庫合集(連結在下方)

phpStudy安裝所需運行函式庫集合下載

VC9 32位

VC9 32位

VC9 32位元 phpstudy整合安裝環境運行庫

php程式設計師工具箱完整版

php程式設計師工具箱完整版

程式設計師工具箱 v1.0 php整合環境

VC11 32位

VC11 32位

VC11 32位元 phpstudy整合安裝環境運行庫

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用