Skip to main content
 首页 » 编程设计

python之为什么 Pandas 有自己的日期时间对象时间戳

2024年12月31日11txw1958

pandas.Timestamp 的文档陈述了每个 pandas 用户都熟知的概念:

Timestamp is the pandas equivalent of python’s Datetime and is interchangeable with it in most cases.

但我完全不明白为什么需要 pandas.Timestamps。 为什么使用与 python 的 Datetime 不同的对象是有用的?简单地从日期时间构建 pandas.DatetimeIndex 不是更干净吗?

请您参考如下方法:

您可以查看 Pandas 文档了解详细信息:

"pandas.Timestamp" is a replacement for python datetime.datetime for Padas usage.

Timestamp is the pandas equivalent of python’s Datetime and is interchangeable with it in most cases. It’s the type used for the entries that make up a DatetimeIndex, and other timeseries oriented data structures in pandas.

Notes

There are essentially three calling conventions for the constructor. The primary form accepts four parameters. They can be passed by position or keyword.

The other two forms mimic the parameters from datetime.datetime. They can be passed by either position or keyword, but not both mixed together.

Timedeltas are differences in times, expressed in difference units, e.g. days, hours, minutes, seconds. They can be both positive and negative.

Timedelta is a subclass of datetime.timedelta, and behaves in a similar manner, but allows compatibility with np.timedelta64 types as well as a host of custom representation, parsing, and attributes.

我想说,由于 pandas 可以更好地处理时间序列数据,因此它是对原始内置日期时间模块的一种扭曲。

The weaknesses of Python's datetime format inspired the NumPy team to add a set of native time series data type to NumPy. The datetime64 dtype encodes dates as 64-bit integers, and thus allows arrays of dates to be represented very compactly.