简体   繁体   English

两个不同的周数评估到相同的日期

[英]Two different week numbers evaluated to same date

I'm parsing weekly time series data from a source that shows dates using a year and week number. 我正在解析来自显示使用年份和周数的日期的来源的每周时间序列数据。 However, when trying to use Python's datetime.strptime function to turn these into YYYY-MM-DD dates, two different week numbers sometimes evaluate to the same date, when I know that they should not. 但是,当尝试使用Python的datetime.strptime函数将它们转换为YYYY-MM-DD日期时,两个不同的周数有时会计算到相同的日期,当我知道它们不应该。 The weekly data is for the week ending on a Friday. 每周数据是在星期五结束的一周。 For example: 例如:

datetime.strptime("1998-5-53", "%Y-%w-%U")
Out[43]: datetime.datetime(1999, 1, 8, 0, 0)

datetime.strptime("1999-5-01", "%Y-%w-%U")
Out[44]: datetime.datetime(1999, 1, 8, 0, 0)

The underlying data from the European Central Bank; 来自欧洲中央银行的基础数据; an example series is here . 这里有一个示例系列。

1998 did not have 53 weeks; 1998年没有53周; December 31st is week 52: 12月31日是第52周:

>>> datetime.strptime("1998-4-52", "%Y-%w-%U")
datetime.datetime(1998, 12, 31, 0, 0)

Note that the documentation for %U states: 请注意%U的文档说明:

Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. 一年中的周数(星期日作为一周的第一天)作为十进制数[00,53]。 All days in a new year preceding the first Sunday are considered to be in week 0. 在第一个星期日之前的新年中的所有日子都被认为是在第0周。

It could be that your data source sees the days preceding the first sunday as week 1 instead. 可能是您的数据源将第一个星期日之前的日期视为第1周。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在相同数据和相同算法上进行评估时,为什么会产生两个不同的AUC分数 - Why two different AUC scores are produced when evaluated on same data and same algorithm 用熊猫计数(同一行中有两个不同的数字) - Counting with pandas (two different numbers at the same row) 检查数字是否在两个不同数字的相同位置 - check if digit is at same position in two different numbers 日期时间库具有相同日期的两个不同秒 - two different second with the same date by datetime library 基于日期的带有周数的列表列表 - list of lists with week numbers based on date SELECT BETWEEN to date 和同一日期的两个不同时间 - SELECT BETWEEN to date and two different times in the same date 在Sql中按日期和同一日期的两个不同时间分组 - group by date and two different times in the same date in Sql 使用 python 获取两个日期之间的周数 - Get the week numbers between two dates with python 在两台不同的计算机上用python中的种子生成相同的“随机数” - Generating the same "random numbers" with a seed in python on two different computers 为什么两个不同的数字在元组中返回相同的字符串? - Why is it that two different numbers return the same string in a tuple?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM