I have been trying to filter my data frame for the specific date although the date is present in the data frame but it doesn't return any results
Data in Data frame based on query
df[df['Date'] > '2017-03-20']
returns this results
StaffID Date
90047 2017-03-20 19:00:00
90049 2017-03-20 19:00:00
90049 2017-03-27 19:00:00
although when i am running this query
df[df['Date'] == '2017-03-20']
or
df.loc[df['Date'] == '2017-03-20']
it returns me no results at all just an empty data frame
StaffID Date
my data frame column types are
StaffID int64
Date datetime64[ns]
and i have tried above query by comparing data frame date with string as well as by converting the string date into datetime64[ns] still the same results any help please would be appreciated
Use dt.date astype string then compare i.e
df[df['Date'].dt.date.astype(str) == '2017-03-20']
Output:
StaffID Date 0 90047 2017-03-20 19:00:00 1 90049 2017-03-20 19:00:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With