对于Pandas,您应该使用矢量化操作:
# convert series to datetime, if not already
df['last_login'] = pd.to_datetime(df['last_login'])
# calculate Boolean series mask
mask = df['last_login'].dt.normalize() == pd.to_datetime('today')
# apply mask
df_filtered = df[mask]
# optionally, convert to list of lists
df_filtered_L = df_filtered.values.tolist()
datetime
级数将时间分量展平为零,因此可以将其与
pd.to_datetime('today')
,这已经正常化了。
pd.to_datetime('now').normalize() == pd.to_datetime('today')
返回
True
.