Python pandas Timestamp.week在一年的第一天返回52 [英] Python pandas Timestamp.week returns 52 for first day of year

查看:50
本文介绍了Python pandas Timestamp.week在一年的第一天返回52的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码返回52 52:怎么来?

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)

推荐答案

这是正确的,这是 ISO周日期.

上周

ISO周编号年份的最后一周,即第52周或第53周,是第01周之前的一周.本周的属性为:

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:

  • 它有一年的最后一个星期四.
  • 这是最后一周,其中12月的日子占多数(4个或更多).
  • 它的中间一天,星期四,是最后一年.
  • 最后一天是最接近12月31日的星期日.
  • 它有12月28日.因此,上周最早的时间可能从12月22日星期一延长至12月28日星期日,上周的最新时间可能是将12月28日星期一延长至1月3日星期日(公历第二年).
  • 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).

如果12月31日是星期一,星期二或星期三,则在第二年的第01周.如果是星期四,则是在该年的第53周刚结束;如果在星期五是在第52周(如果刚结束的年份是a年,则是53);如果是在周六或周日,则是在该年的第52周刚刚结束.

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.

这篇关于Python pandas Timestamp.week在一年的第一天返回52的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆