Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 552
Antoine Gautier Avatar asked Jun 05 '17 15:06

Antoine Gautier


Video Answer


1 Answers

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.

like image 160
mx0 Avatar answered Oct 06 '22 00:10

mx0