I downloaded a dataset from the internet which contains the data related to daily transactions in the following format [dummy values mentioned below] :
ID Date Item1 Item2 Item3 Item4 Item5
0 2017-08-28 1234 5678 91011 1213 1415
1 2017-07-27 1234 5678 91011 1213 1415
2 2017-06-26 1234 5678 91011 1213 1415
3 2017-05-25 1234 5678 91011 1213 1415
How do I use the date column to get the values for the transactions that happened in the last week , month and the last 3 months ?
I used this to format the date in the pandas format:
df['week'] = pd.to_datetime(df['week'])
And tried to get the values in the last week using this :
range_max = df['week'].max()
range_min = range_max - dt.timedelta(days=7)
# take slice with final week of data
sliced_df = df[(df['week'] >= range_min) & (df['week'] <= range_max)]
This works for retrieving last week's data , but how do I retrieve values for , say, a specific month or week ?