I have a dataframe with 1000 records. I am trying to filter only the below Dates record from the df
2020-06-09
2020-08-06
2020-08-25
I have tried the below code hoping that my code will filter only those records available for that particular date.
df[(df['Date'] == '2020-06-09') & (df['Date'] = '2020-08-06') & (df['Date'] = '2020-08-25')]
But i am not getting any output. I need to view the dataframe only for those particular dates.
You can use isin
:
df = df[df['date'].isin(['2020-06-09', '2020-08-06', '2020-08-25'])]
Method 2
dates = ['2020-06-09', '2020-08-06', '2020-08-25']
df = df.query("date in @dates")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.