我认为您需要to_datetime
,如果第一个数字是天,请添加参数dayfirst=True
:
print (msft)
Title plan run status Tested On
0 A P0 P0 Passed 11/08/2018 8:42 AM
1 B P0 P0 Failed 12/08/2018 8:42 AM
2 C - Canary Passed 10/08/2018 8:42 AM
3 D - Sanity Blocked 11/08/2018 8:42 AM
msft['Tested On'] = pd.to_datetime(msft['Tested On'], dayfirst=True)
print (msft)
Title plan run status Tested On
0 A P0 P0 Passed 2018-08-11 08:42:00
1 B P0 P0 Failed 2018-08-12 08:42:00
2 C - Canary Passed 2018-08-10 08:42:00
3 D - Sanity Blocked 2018-08-11 08:42:00
然后删除时间dt.floor
并进行比较:
df = msft[msft['Tested On'].dt.floor('d') == '2018-08-11']
print (df)
Title plan run status Tested On
0 A P0 P0 Passed 2018-08-11 08:42:00
3 D - Sanity Blocked 2018-08-11 08:42:00
详情:
print (msft['Tested On'].dt.floor('d'))
0 2018-08-11
1 2018-08-12
2 2018-08-10
3 2018-08-11
Name: Tested On, dtype: datetime64[ns]