I open .xslx with pandas.
value | date of pickup |
---|---|
ABC123 | 03.08.2022 11:24 |
ABC234 | 27.07.2022 15:45 |
ABC434 | 18.05.2022 02:35 |
ABVC122 | 28.07.2022 10:10 |
I need to keep only rows for previuos week. In my example today is 03.08.2022 wk number 31 I expect to see these rows:
value | date of pickup |
---|---|
ABC234 | 27.07.2022 15:45 |
ABVC122 | 28.07.2022 10:10 |
I tried this: #remove week_num not in range df = df.drop([datetime.date(df['date of pickup']).isocalendar()[1] != weekly_num])
Do you have any ideas?
Thank you for your support Angelo
CodePudding user response:
You can use something like this
import pandas as pd
import datetime
df = pd.DataFrame({'value':['a', 'b', 'c', 'd'], 'date':pd.date_range("2022-07-01", "2022-08-03", periods=4)})
df[(df['date'] <= pd.to_datetime("today") - datetime.timedelta(weeks=1)) & (df['date'] >= pd.to_datetime("today") - datetime.timedelta(weeks=2))]
output
value date
c 2022-07-23
Next time if you can provide the dataframe creation code, it will be easier for us to answer your question.