我从RBR.csv创建了一个数据帧df2,并希望仅在start:18-04-2015 21:30和End:18-09-2015 14:09之间使用数据设置为dataframe df3
In [12]:
df3 = df2[(df2['date']>=datetime.datetime(18-04-2015 21:30)) &
(df2['date'] <= datetime.datetime(18-09-2015 14:09))]
File "<ipython-input-12-95bbb0030f0a>", line 1
df3 = df2[(df2['date']>=datetime.datetime(18-04-2015 21:30)) &
(df2['date'] <= datetime.datetime(18-09-2015 14:09))]
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
您需要正确创建datetime.datetime
个实例:
df3 = df2[(df2['date'] >= datetime.datetime(2015, 4, 18, 21, 30)) &
(df2['date'] <= datetime.datetime(2015, 9, 18, 14, 9))]
或者,您可以使用字符串:
df3 = df2[(df2['date'] >= '18-04-2015 21:30') & (df2['date'] <= '18-09-2015 14:09')]