I have a pandas dataframe with a lot of columns, some of which have values on weekends.
I'm now trying to remove all weekend rows, but need to add the values I remove to the respective following Monday.
Thu: 4
Fri: 5
Sat: 2
Sun: 1
Mon: 4
Tue: 3
needs to become
Thu: 4
Fri: 5
Mon: 7
Tue: 3
I have figured out how to slice only the weekdays (using df.index.dayofweek), but can't think of a clever way to aggregate before doing so.
Here's some dummy code to start:
index = pd.date_range(datetime.datetime.now().date() -
datetime.timedelta(20),
periods = 20,
freq = 'D')
df = pd.DataFrame({
'Val_1': np.random.rand(20),
'Val_2': np.random.rand(20),
'Val_3': np.random.rand(20)
},
index = index)
df['Weekday'] = df.index.dayofweek
Any help on this would be much appreciated!