I have a use case where I need to count the server failures for current week. I am counting by reading a file where all the dates and failures are given. But I need to Calculate weekly failures, So I thought of to get all the dates in current week and compare that with dates in file and hence count the failures. So the question is how can I get all the dates of current week ? Also, how can i check if any date comes in that week? Can anyone please help ?
Asked
Active
Viewed 262 times
0
-
1Does this answer your question? [Getting the date of the first day of the week](https://stackoverflow.com/questions/39441639/getting-the-date-of-the-first-day-of-the-week) – Ken Y-N Nov 17 '21 at 06:36
-
And to advance a day, [please consult these answers](https://stackoverflow.com/q/3240458/1270789). – Ken Y-N Nov 17 '21 at 06:37
-
No, it doesn't actually. I have already done whats there in please consult these answers. I am looking for something better. I need dates of all the days in current week so far. – user12252991 Nov 17 '21 at 06:43
-
2Ahh, ok! you are saying to use both the above links. Calculate first day of the week and then get the dates for rest of the days. Let me try that. – user12252991 Nov 17 '21 at 06:45
2 Answers
0
Using pandas:
df.loc[df["dates"].dt.week == week_number]
This simply gets all the rows where week is equal to the specified week (you can find out that week by trying a dummy value and using .dt.week
).

Larry the Llama
- 958
- 3
- 13
0
print(date.today())
for x in range(7):
print(date.today() + timedelta(days=x))