How to cancel specific date in dataframe?
As title I have a data named user like
reporttime
0 2020-01-01 00:00:17
1 2020-01-01 00:03:17
2 2020-01-01 00:06:17
3 2020-01-01 00:09:17
. .
. .
. .
2020-12-30 23:59:04
and I want to delete all data about 2020-01-02
So I try
user.drop(user[(user['reporttime'].dt.month.isin(np.arange(0,1)))(user['reporttime'].dt.day.isin(np.arange(2,3)))],axis = 1,inplace= True)
But it failed and it drop all data where am i doing wrong?
You might use .dt.date
to access date, consider following example:
import pandas as pd
import datetime
df = pd.DataFrame({"reporttime":pd.to_datetime(["2020-01-01 00:00:17","2020-01-01 00:09:17","2020-12-30 23:59:04"])})
df2 = df[df['reporttime'].dt.date != datetime.date(2020,1,1)]
print(df2)
output
reporttime
2 2020-12-30 23:59:04
Note: I limited initial df
to 3 records for brevity sake.