Home > Blockchain >  How can I get all the dates of current week?
How can I get all the dates of current week?

Time:11-17

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 ?

CodePudding user response:

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).

CodePudding user response:

print(date.today())
for x in range(7):
    print(date.today()   timedelta(days=x))
  • Related