1 回答
TA贡献1804条经验 获得超3个赞
您可以按布尔索引
和系列.dt.时间按时间
筛选日期时间:
print (df)
a date b
0 123412 2020-03-26 12:00:00 NaN
1 123412 2020-03-27 12:00:00 NaN
2 123412 2020-03-27 09:00:00 NaN
3 123412 2020-03-27 09:00:00 NaN
4 123412 2020-03-27 15:00:00 NaN
5 123412 2020-03-26 15:00:00 NaN
6 123412 2020-03-27 11:00:00 NaN
7 123412 2020-03-27 12:00:00 NaN
d = '2020-03-26 12:00'
df = df[df['date'].dt.time.eq(pd.Timestamp(d).time())]
print (df)
a date b
0 123412 2020-03-26 12:00:00 NaN
1 123412 2020-03-27 12:00:00 NaN
7 123412 2020-03-27 12:00:00 NaN
如果只需要唯一的日期时间:
d = '2020-03-26 12:00'
df = df.drop_duplicates('date')
df = df[df['date'].dt.time.eq(pd.Timestamp(d).time())]
print (df)
a date b
0 123412 2020-03-26 12:00:00 NaN
1 123412 2020-03-27 12:00:00 NaN
添加回答
举报