Skip to content Skip to sidebar Skip to footer

Python Pandas Timestamp.week Returns 52 For First Day Of Year

The code below returns 52 52: how come? import pandas as pd ts = pd.Timestamp('01-01-2017 12:00:00') print(ts.weekofyear, ts.week)

Solution 1:

This is correct, that's ISO week date.

Last week

The last week of the ISO week-numbering year, i.e. the 52nd or 53rd one, is the week before week 01. This week’s properties are:

  • It has the year's last Thursday in it.
  • It is the last week with a majority (4 or more) of its days in December.
  • Its middle day, Thursday, falls in the ending year.
  • Its last day is the Sunday nearest to 31 December.
  • It has 28 December in it. Hence the earliest possible last week extends from Monday 22 December to Sunday 28 December, the latest possible last week extends from Monday 28 December to Sunday 3 January (next gregorian year).

If 31 December is on a Monday, Tuesday or Wednesday, it is in week 01 of the next year. If it is on a Thursday, it is in week 53 of the year just ending; if on a Friday it is in week 52 (or 53 if the year just ending is a leap year); if on a Saturday or Sunday, it is in week 52 of the year just ending.


Post a Comment for "Python Pandas Timestamp.week Returns 52 For First Day Of Year"