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