Python pandas Timestamp.week returns 52 for first day of year

The code below returns 52 52

: how did it happen?

import pandas as pd
ts = pd.Timestamp('01-01-2017 12:00:00')
print(ts.weekofyear, ts.week)

      

+3


source to share


1 answer


It is correct that the date of the week is ISO .



Last week

The last week of the ISO numbering year, ie 52nd or 53rd, is the week before week 01. Properties of this week:

  • This year passed last year.
  • This is the last week with most (4 or more) days in December.
  • Its average day, Thursday, is at the end of the year.
  • The last day is the Sunday closest to December 31st.
  • It contains December 28th. Therefore, the earliest possible last week runs from Monday December 22 to Sunday December 28, the last possible last week runs from Monday December 28 to Sunday January 3 (next Gregorian year).

If December 31st is Monday, Tuesday or Wednesday, then week 01 of the following year. If it takes place on Thursday, it will be in the 53rd week of the just ended; if on Friday it is in week 52 (or 53 if the end year is a leap year); if on Saturday or Sunday it only ends on the 52nd week.

+6


source







All Articles