如何使用datetime64值过滤Pandas数据框?
使用字符串基本值,可以进行过滤:
df = df[df['date_in_string_format'] < '2017-07-01']
=&GT;成功
使用datetime64格式的系列,我收到错误:
df['date_in_datetime64_format'] = map(pd.to_datetime, \
df['date_in_string_format'], '%Y-%m-%d')
df = df[df['date_in_datetime64_format'] < pd.datetime(2017,7,1)]
=&GT;结果:
'<' not supported between instances of 'map' and 'datetime.datetime'
答案 0 :(得分:0)
我不明白为什么我们需要map
df=pd.DataFrame({'Date':['2017-01-01','2017-07-19']})
df['Date'] = pd.to_datetime(df['Date'])
df[df['Date'] < pd.datetime(2017,7,1)]
Out[1674]:
Date
0 2017-01-01