Nons
Nons

Reputation: 207

How to get the rows which in between some date

i have excel sheet which is below

id date
1 Friday, June 26, 2020
2 Sunday, June 26, 2018
3 Sunday, June 26, 2019

First i need to convert Sunday, June 26, 2019 to Sunday, June 26, 2019 to 26/06/2019

    import pandas as pd
    df = pd.read_excel(r"test.xlsx",sheet_name = 'Sheet1')
    new_data = (df['date'] > '01/12/2020') & (df['date'] <= date.today())

Upvotes: 1

Views: 341

Answers (1)

jezrael
jezrael

Reputation: 862731

First convert values to datetimes by to_datetime and then use similar like your solution with today with Timestamp.floor for remove times from datetimes (set times to 00:00:00):

print (df)
   id                      date
0   1  Friday, January 26, 2021 <- added datetimes for matching
1   2     Sunday, June 26, 2018
2   3     Sunday, June 26, 2019

df['date']= pd.to_datetime(df['date'], format='%A, %B %d, %Y')

today = pd.to_datetime('now').floor('d')
df1 = df[(df['date']> '2020-12-01') & (df['date']<= today)]

print (df1)
   id       date
0   1 2021-01-26

Upvotes: 1

Related Questions