'How to replace by the last monday each day of my variable Dates

Here's my dataframe :

dataframe

I want the CA by week so I made this :

df['Date'] = pd.to_datetime(df['Date']) - pd.to_timedelta(7, unit='d')
df_output = df.groupby(['ID', pd.Grouper(key='Date', freq='W-MON')])['Price'].sum().reset_index().sort_values('Date')

Here's the output :

output_price_by_week

But I cannot figure it out how to merge those two dataframe. I need to merge them by ID and Date but the variable Date in the seconde dataframe (price_by_week) have only the monday so I cannot merged them together, it will be dysfunctional because they're not the same anymore.

So I tought of something, I need to change the date in the first dataframe and replace by the previous monday all the day of the week and so on.

Something like that :

2019-10-14 -> 2019-10-14 (it's a monday)
2019-10-16 -> 2019-10-14
2019-10-18 -> 2019-10-14
2019-10-21 -> 2019-10-21 (another monday)
2019-10-23 -> 2019-10-21

And so on, like that I could merge and have the price by week for each day

I didn't find anything how to do that, any tips or ideas ?

EDIT : Found a solution after hours of search :)

day_monday = []

for jour in df['Date']:
    day = str(jour)
    day = day[:-9]
    print(day)
    dt = datetime.strptime(day, '%Y-%m-%d')
    start = dt - timedelta(days=dt.weekday())
    day_monday.append(start)

I think it work, if someone here could confirm ?



Solution 1:[1]

Moving the .animation from the group to the navigation view fixes this issue. I moved .animation to directly under .navigationViewStyle and removed the value:

Answered on apple developer forums:

https://developer.apple.com/forums/thread/698407

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MostPalone