Hi I have the following data:
index, Day of week, Week no, Fecha
360 Friday 52 2019-12-27
361 Saturday 52 2019-12-28
362 Sunday 53 2019-12-29
363 Monday 53 2019-12-30
364 Tuesday 53 2019-12-31
365 Wednesday 1 2020-01-01
366 Thursday 1 2020-01-02
367 Friday 1 2020-01-03
368 Saturday 1 2020-01-04
369 Sunday 2 2020-01-05
370 Monday 2 2020-01-06
I would like:
-the week that contains the first of January to be week no 1
-to have the weeks start on Sunday
-to have week no 1 as a full week of 7 days, meaning the 29th, 30th and 31th of December to also get week no 1.
-to get this to work also when I have a lot of years in this data set.
In this particular year it means changing all 53's to 1's but I think there might be other years where this won't work. So to get a general rule, I realized if the first of January falls on a Sunday I don't need to change anything so I thought to first check that for every year and if the first of January doesn't fall on a Sunday to change all the week no's between the previous Sunday and that Sunday to 1. Another option I thought of is to find out what week no the previous Sunday has and then to change all week no's of that year with the same number as the previous Sunday, to 1.
For both I would need to do a condition within a df to only filter out certain rows but how do I do that when I only want to display one column of that df? Meaning if I would do:
totals[(totals['Fecha'].dt.month==1) & (totals['Fecha'].dt.day==1) & (totals['Fecha'].dt.year==i)]
then this would show all columns in totals while I would want and these conditions and to only see column 'Week day'.
So how would I do that and also, this all sounds super complicated to me. Is there an easier/more efficient way to this that I overlooked?
Thank you!