Wednesday, 15 March 2023

Python - Push forward weekend values to Monday

I have a dataframe (called df) that looks like this:

df

I'm trying to take all weekend 'Volume' values (the ones where column 'WEEKDAY'=5 (saturday) or 6(sunday)) and sum them to the subsequent monday(WEEKDAY=0).

I tried a few things but nothing really worked, taking an example from the last three rows:

What I have

What I'm expecting is this:

What I expect

To reproduce the problem:

!wget https://raw.githubusercontent.com/brunodifranco/TCC/main/volume_por_dia.csv

df = pd.read_csv('volume_por_dia.csv').sort_values('Datas',ascending=True)
df['Datas'] = pd.to_datetime(df['Datas'])
df = df_volume_noticias.set_index('Datas')
df['WEEKDAY'] = df.index.dayofweek
df


from Python - Push forward weekend values to Monday

No comments:

Post a Comment