write some python code, very easy 5 minute job
Budget: £10 – £20 GBP
I have a very small amount of python code that i need written. It should probably only take 5 minutes to write but I'm new to python so it would take me a lot longer. Here are some details.
I have a pandas dataframe, something like this one shown below:
league match_date team
Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272
Argentine Division 1 4/7/2022 272
Argentine Division 1 6/25/2022 272
Argentine Division 1 6/21/2022 272
Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283
Argentine Division 1 3/7/2022 283
Argentine Division 1 6/25/2022 283
Argentine Division 1 3/7/2022 299
Argentine Division 1 6/26/2022 299
Argentine Division 1 6/20/2022 299
I need to edit the dates in the match_date column using the following criteria:
if the match_date = 12/25/2022 then leave the match_date unchanged.
if the match_date != 12/25/2022 then subtract 7 days from the match_date above.
So the first date below the cell match_date = 12/25/2022 would become match_date = 12/18/2022.
Continue this for the remaining rows. So below the cell match_date = 12/18/2022 would be match_date = 12/11/2022 and below that would be match_date = 12/04/2022 etc.
However when the value in the last column 'team' changes, for instance from 272 to 283 or from 283 to 299, I want the process to start again subtracting 7 days from 12/25/2022 and not the cell above.
The dates should update from the dataframe on the left to the dataframe on the right:
league match_date team league match_date team
Argentine Division 1 12/25/2022 272 Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272 Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272 Argentine Division 1 12/25/2022 272
Argentine Division 1 4/7/2022 272 Argentine Division 1 12/18/2022 272
Argentine Division 1 6/25/2022 272 Argentine Division 1 12/11/2022 272
Argentine Division 1 6/21/2022 272 Argentine Division 1 12/4/2022 272
Argentine Division 1 12/25/2022 283 Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283 Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283 Argentine Division 1 12/25/2022 283
Argentine Division 1 3/7/2022 283 Argentine Division 1 12/18/2022 283
Argentine Division 1 6/25/2022 283 Argentine Division 1 12/11/2022 283
Argentine Division 1 3/7/2022 299 Argentine Division 1 12/18/2022 299
Argentine Division 1 6/26/2022 299 Argentine Division 1 12/11/2022 299
Argentine Division 1 6/20/2022 299 Argentine Division 1 12/4/2022 299
I have a pandas dataframe, something like this one shown below:
league match_date team
Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272
Argentine Division 1 4/7/2022 272
Argentine Division 1 6/25/2022 272
Argentine Division 1 6/21/2022 272
Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283
Argentine Division 1 3/7/2022 283
Argentine Division 1 6/25/2022 283
Argentine Division 1 3/7/2022 299
Argentine Division 1 6/26/2022 299
Argentine Division 1 6/20/2022 299
I need to edit the dates in the match_date column using the following criteria:
if the match_date = 12/25/2022 then leave the match_date unchanged.
if the match_date != 12/25/2022 then subtract 7 days from the match_date above.
So the first date below the cell match_date = 12/25/2022 would become match_date = 12/18/2022.
Continue this for the remaining rows. So below the cell match_date = 12/18/2022 would be match_date = 12/11/2022 and below that would be match_date = 12/04/2022 etc.
However when the value in the last column 'team' changes, for instance from 272 to 283 or from 283 to 299, I want the process to start again subtracting 7 days from 12/25/2022 and not the cell above.
The dates should update from the dataframe on the left to the dataframe on the right:
league match_date team league match_date team
Argentine Division 1 12/25/2022 272 Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272 Argentine Division 1 12/25/2022 272
Argentine Division 1 12/25/2022 272 Argentine Division 1 12/25/2022 272
Argentine Division 1 4/7/2022 272 Argentine Division 1 12/18/2022 272
Argentine Division 1 6/25/2022 272 Argentine Division 1 12/11/2022 272
Argentine Division 1 6/21/2022 272 Argentine Division 1 12/4/2022 272
Argentine Division 1 12/25/2022 283 Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283 Argentine Division 1 12/25/2022 283
Argentine Division 1 12/25/2022 283 Argentine Division 1 12/25/2022 283
Argentine Division 1 3/7/2022 283 Argentine Division 1 12/18/2022 283
Argentine Division 1 6/25/2022 283 Argentine Division 1 12/11/2022 283
Argentine Division 1 3/7/2022 299 Argentine Division 1 12/18/2022 299
Argentine Division 1 6/26/2022 299 Argentine Division 1 12/11/2022 299
Argentine Division 1 6/20/2022 299 Argentine Division 1 12/4/2022 299