当前位置: 代码迷 >> python >> Python - Pandas - 时间戳和周期范围之间的差异
  详细解决方案

Python - Pandas - 时间戳和周期范围之间的差异

热度:65   发布时间:2023-06-16 14:12:42.0

我很难理解PeriodIndex和DateTimeIndex之间的区别,以及何时使用它。 特别是,使用Periods而不是Timestamps似乎更自然,但最近我发现Timestamps似乎提供了相同的索引功能,可以与timegrouper一起使用,并且还可以更好地使用Matplotlib的日期功能。 所以我想知道是否有任何理由使用Periods(PeriodIndex)?

期间可用于检查特定事件是否在特定时期内发生。 基本上,Period表示时间间隔,而Timestamp表示时间点。

# For example, this will return True since the period is 1Day. This test cannot be done with a Timestamp. 
p = pd.Period('2017-06-13')
test = pd.Timestamp('2017-06-13 22:11')
p.start_time < test < p.end_time

我认为使用Periods / Timestamps的最简单的原因是他/她的代码是否需要来自Period和Timestamp的属性。