I have a data frame like the following
transaction_no sales_order is_delivered dispatch_date remarks ....
0 2122.0 1.0 True 06-01-2020 NaN
1 2122.0 1.0 True 06-01-2020 NaN
2 2122.0 1.0 True 06-01-2020 NaN
3 2122.0 1.0 True 06-01-2020 NaN
4 2122.0 1.0 True 06-01-2020 NaN
I want to select rows based on a date range criteria but I am getting the empty dataframe every time
Here's what I did:
dt_format = '%Y-%m-%d %H:%M'
o_f = datetime.strptime(request.GET['from'], dt_format).strftime('%d/%m/%Y')
o_t = datetime.strptime(request.GET['to'], dt_format).strftime('%d/%m/%Y')
f = datetime.strptime(request.GET['from'], dt_format).replace(tzinfo=pytz.UTC).date().strftime("%d-%m-%Y")
t = datetime.strptime(request.GET['to'], dt_format).replace(tzinfo=pytz.UTC).date().strftime("%d-%m-%Y")
allot_df = allot_df[allot_df['dispatch_date'].isin(pd.date_range(f, t))]
How can I do that ? Better yet why is this not working?
Update:
The type of column was str
so I changed it to datetime
allot_df['dispatch_date'] = pd.to_datetime(allot_df['dispatch_date'])
allot_df = allot_df[allot_df['dispatch_date'].isin(pd.date_range(f, t))]
But now the whole dataframe comes as the output