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,
Split Date field using re.split
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,