标量#
数组#
For most data types, pandas uses NumPy arrays as the concrete
objects contained with a Index, Series, or
DataFrame.
时间差 |
(无) |
||
|---|---|---|---|
Period … |
|||
|
|||
|
|||
Categorical |
|||
稀疏 |
|||
PyArrow |
Python 标量或 PyArrow |
||
PyArrow |
Python Scalars or |
pandas and third-party libraries can extend NumPy’s type system (see 扩展类型).
The top-level array() method can be used to create a new array, which may be
stored in a Series, Index, or as a column in a DataFrame.
|
创建一个数组。 |
PyArrow#
警告
此功能为实验性功能,API 可能在未来版本中修改,恕不另行通知。
arrays.ArrowExtensionArray 由 pyarrow.ChunkedArray 支持,并使用 pyarrow.DataType 而非 NumPy 数组和数据类型。 arrays.ArrowExtensionArray 的 .dtype 是一个 ArrowDtype 。
Pyarrow 提供了与 NumPy 类似的数组和 data type 支持,包括所有数据类型的头等空值支持、不可变性等。
下表显示了 pandas 识别的 Pyarrow 支持的(pa)、pandas 扩展和 NumPy(np)的等效类型。下表中的 Pyarrow 支持的类型需要传递给 ArrowDtype 才能被 pandas 识别,例如 pd.ArrowDtype(pa.bool_())
PyArrow 类型 |
pandas 扩展类型 |
NumPy 类型 |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
备注
Pyarrow 支持的字符串由 pd.StringDtype("pyarrow") 和 pd.ArrowDtype(pa.string()) 提供。 pd.StringDtype("pyarrow") 在 string section 中有介绍,当指定字符串别名 "string[pyarrow]" 时会被返回。 pd.ArrowDtype(pa.string()) 通常与 ArrowDtype 的其他类型具有更好的互操作性。
arrays.ArrowExtensionArray 中的单个值存储为 PyArrow 对象,但标量值会以与数据类型对应的 Python 标量形式**返回**,例如,PyArrow int64 将返回为 Python int,缺失值返回为 NA 。
|
基于 PyArrow ChunkedArray 的 Pandas 扩展数组。 |
|
Arrow 的数据类型的扩展类型。 |
更多信息,请参阅 PyArrow user guide
日期时间#
NumPy 无法原生表示带时区的日期时间。pandas 通过 arrays.DatetimeArray 扩展数组来支持此功能,该数组可以包含带时区或不带时区的日期时间值。
Timestamp 是 datetime.datetime 的子类,是 pandas 用于带时区或不带时区的日期时间数据的标量类型。NaT 是日期时间数据的缺失值。
|
Python datetime.datetime 对象的 Pandas 替代。 |
属性#
返回 numpy datetime64 格式(以纳秒为单位)。 |
|
返回星期几。 |
|
返回星期几。 |
|
返回一年中的第几天。 |
|
返回一年中的第几天。 |
|
|
返回月份中的天数。 |
|
返回月份中的天数。 |
|
|
|
|
|
如果年份是闰年,则返回 True。 |
|
检查日期是否为月份的最后一天。 |
|
检查日期是否为月份的第一天。 |
|
检查日期是否为季度的最后一天。 |
|
检查日期是否为季度的第一天。 |
|
如果日期是该年的最后一天,则返回 True。 |
|
如果日期是该年的第一天,则返回 True。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
返回一年中的季度。 |
|
|
|
|
|
tzinfo 的别名。 |
|
|
|
与 self._creso 关联的缩写。 |
|
|
|
返回一年中的周数。 |
|
返回一年中的周数。 |
|
Methods#
|
将底层的 int64 表示转换为给定的单位。 |
|
将时区感知的 Timestamp 转换为另一个时区。 |
|
返回一个新的 Timestamp,其值向上取整到此分辨率。 |
|
组合日期和时间,得到具有相同日期和时间字段的 datetime。 |
|
返回 ctime() 风格的字符串。 |
|
返回具有相同年、月、日的 date 对象。 |
|
返回具有指定区域设置的 Timestamp 的日期名称。 |
|
返回夏令时 (DST) 调整。 |
|
返回一个新的 Timestamp,其值向下取整到此分辨率。 |
|
从序数(proleptic Gregorian ordinal)构造时间戳。 |
|
根据 POSIX 时间戳将 timestamp[, tz] 转换为 tz 的本地时间。 |
|
返回一个命名元组,包含 ISO 年、周数和星期几。 |
|
按 ISO 8601 格式返回时间。 |
|
返回日期所代表的星期几。 |
|
使用指定的 locale 返回 Timestamp 的月份名称。 |
|
将 Timestamp 规范化到午夜,保留 tz 信息。 |
|
返回新的 Timestamp 对象,表示 tz 的当前本地时间。 |
|
实现 datetime.replace,处理纳秒。 |
|
将 Timestamp 四舍五入到指定的精度。 |
|
返回 Timestamp 的格式化字符串。 |
|
函数未实现。 |
|
返回时间对象,具有相同的时间,但 tzinfo=None。 |
|
返回 POSIX 时间戳(float 类型)。 |
|
返回时间元组,与 time.localtime() 兼容。 |
|
返回时间对象,具有相同的时间和 tzinfo。 |
|
返回具有相同精度的 numpy.datetime64 对象。 |
|
将 Timestamp 转换为 NumPy datetime64。 |
|
将 TimeStamp 转换为儒略日。 |
|
返回此时间戳是其观测值的周期。 |
|
将 Timestamp 对象转换为本地 Python datetime 对象。 |
|
返回本地时区的当前时间。 |
|
返回序数(proleptic Gregorian ordinal)。 |
|
将时区感知的 Timestamp 转换为另一个时区。 |
|
将 Timestamp 本地化到某个时区。 |
|
返回时区名称。 |
从 POSIX 时间戳构造一个时区感知的 UTC 日期时间。 |
|
返回一个新的 Timestamp,表示 UTC 的日期和时间。 |
|
返回 UTC 偏移量。 |
|
返回 UTC 时间元组,与 time.localtime() 兼容。 |
|
返回日期所代表的星期几。 |
一组时间戳可以存储在 arrays.DatetimeArray 中。对于带有时区的数据,arrays.DatetimeArray 的 .dtype 是 DatetimeTZDtype 。对于不带时区的数据,则使用 np.dtype("datetime64[ns]")。
如果数据带有时区,则数组中的每个值都必须具有相同的时区。
|
pandas 的时区无关或时区感知日期时间数据的扩展数组。 |
|
用于时区感知日期时间数据的 ExtensionDtype。 |
Period#
NumPy 可以原生表示时间差。pandas 提供了 Timedelta 来与 Timestamp 对称。NaT 是 timedelta 数据的缺失值。
|
表示一个持续时间,两个日期或时间之间的差值。 |
属性#
返回一个 numpy timedelta64 数组标量视图。 |
|
返回一个类似命名元组的 components。 |
|
返回 timedelta 的天数。 |
|
返回纳秒数(n),其中 0 <= n < 1 微秒。 |
|
返回 timedelta 的总小时、分钟和秒数(以秒为单位)。 |
|
|
数组视图兼容性。 |
Methods#
|
将底层的 int64 表示转换为给定的单位。 |
|
返回一个新的、向上取整到此分辨率的 Timedelta。 |
|
返回一个新的、向下取整到此分辨率的 Timedelta。 |
将 Timedelta 格式化为 ISO 8601 Duration。 |
|
|
将 Timedelta 四舍五入到指定的分辨率。 |
将 pandas Timedelta 对象转换为 python 的 |
|
返回一个精度为 'ns' 的 numpy.timedelta64 对象。 |
|
|
将 Timedelta 转换为 NumPy timedelta64。 |
持续时间内的总秒数。 |
一组 Timedelta 可以存储在 TimedeltaArray 中。
|
Pandas 扩展数组,用于 timedelta 数据。 |
Period#
pandas 使用 Period 对象来表示时间跨度。
Period#
|
Represents a period of time. |
属性#
获取 Period 所属月份中的日期。 |
|
Period 所属星期几,星期一=0,星期日=6。 |
|
Period 所属星期几,星期一=0,星期日=6。 |
|
返回一年中的第几天。 |
|
返回一年中的第几天。 |
|
获取 Period 所属月份的总天数。 |
|
获取 Period 所属月份的总天数。 |
|
获取 Period 结束时间的 Timestamp。 |
|
返回频率的字符串表示。 |
|
获取 Period 的日小时部分。 |
|
如果 Period 的年份是闰年,则返回 True。 |
|
获取 Period 的小时分钟部分。 |
|
返回 Period 所属的月份。 |
|
返回 Period 所属的季度。 |
|
Fiscal year the Period lies in according to its starting-quarter. |
|
获取 Period 的秒部分。 |
|
获取 Period 开始时间的 Timestamp。 |
|
获取 Period 是一年中的第几周。 |
|
Period 所属星期几,星期一=0,星期日=6。 |
|
获取 Period 是一年中的第几周。 |
|
返回 Period 所属的年份。 |
Methods#
|
将 Period 转换为指定的频率,在区间开始或结束处。 |
|
返回当前日期的 Period。 |
|
返回 |
|
返回 Period 的 Timestamp 表示。 |
:class:`Period 的集合可以存储在 :class:`arrays.PeriodArray 中。:class:`arrays.PeriodArray 中的每个 period 必须具有相同的 freq。
|
用于存储 Period 数据的 Pandas 扩展数组。 |
|
Period 数据的 ExtensionDtype。 |
可空整数#
任意区间可以表示为 :class:`Interval 对象。
Immutable object implementing an Interval, a bounded slice-like interval. |
属性#
String describing the inclusive side the intervals. |
|
Check if the interval is closed on the left side. |
|
Check if the interval is closed on the right side. |
|
Indicates if an interval is empty, meaning it contains no points. |
|
Left bound for the interval. |
|
Return the length of the Interval. |
|
Return the midpoint of the Interval. |
|
Check if the interval is open on the left side. |
|
Check if the interval is open on the right side. |
|
|
Check whether two Interval objects overlap. |
Right bound for the interval. |
区间的集合可以存储在 :class:`arrays.IntervalArray 中。
|
Pandas 数组,用于存储同侧闭合的区间数据。 |
|
用于 Interval 数据的 ExtensionDtype。 |
可空整数#
:class:`numpy.ndarray 无法原生表示带缺失值的整数数据。pandas 通过 :class:`arrays.IntegerArray 提供此功能。
|
整数(可选缺失)值数组。 |
|
An ExtensionDtype for int8 integer data. |
|
An ExtensionDtype for int16 integer data. |
|
An ExtensionDtype for int32 integer data. |
|
An ExtensionDtype for int64 integer data. |
|
用于 uint8 整数数据的 ExtensionDtype。 |
|
用于 uint16 整数数据的 ExtensionDtype。 |
|
用于 uint32 整数数据的 ExtensionDtype。 |
|
用于 uint64 整数数据的 ExtensionDtype。 |
可空浮点数#
|
浮点(可选缺失)值数组。 |
|
An ExtensionDtype for float32 data. |
|
An ExtensionDtype for float64 data. |
分类数据#
pandas 定义了一种自定义数据类型,用于表示只能取有限、固定集合值的数据。:class:`Categorical 的 dtype 可以通过 :class:`CategoricalDtype 来描述。
|
具有类别和有序性的类别数据的类型。 |
一个包含允许的唯一类别的 |
|
分类是否具有有序关系。 |
分类数据可以存储在 :class:`pandas.Categorical 中。
|
以经典的 R / S-plus 风格表示分类变量。 |
当您已经有了类别和整数代码时,可以使用替代的 :meth:`Categorical.from_codes 构造函数:
|
从代码和分类或 dtype 创建 Categorical 类型。 |
dtype 信息可以在 :class:`Categorical 上获取。
此实例 the |
|
此分类的分类。 |
|
分类是否具有有序关系。 |
|
此分类索引的分类代码。 |
np.asarray(categorical) 通过实现数组接口工作。请注意,这会将 :class:`Categorical 转换回 NumPy 数组,因此类别和顺序信息不会被保留!
|
numpy 数组接口。 |
:class:`Categorical 可以存储在 :class:`Series 或 :class:`DataFrame 中。要创建 dtype 为 category 的 Series,请使用 cat = s.astype(dtype) 或 Series(..., dtype=dtype),其中 dtype 可以是
字符串
'category':class:`CategoricalDtype 的实例。
如果 :class:`Series 的 dtype 是 :class:`CategoricalDtype ,则可以使用 Series.cat 来更改分类数据。更多信息请参见 分类 accessor 。
稀疏#
重复多次的单个值(例如 0 或 NaN)的数据可以高效地存储为 :class:`arrays.SparseArray 。
|
用于存储稀疏数据的 ExtensionArray。 |
|
存储在 |
如果 Series 包含稀疏值,则可以使用 Series.sparse 访问器来访问特定于稀疏的属性和方法。更多信息请参阅 稀疏访问器 (Sparse accessor) 和 the user guide 。
PyArrow#
在处理文本数据时,其中每个有效元素都是字符串或缺失值,我们建议使用 StringDtype (别名 "string")。
|
字符串数据的扩展数组。 |
|
|
|
字符串数据的扩展 Dtype。 |
对于由 Series 支持的 arrays.StringArray ,可以使用 Series.str 访问器。更多信息请参阅 字符串处理 。
PyArrow#
布尔数据类型(别名 “boolean”)支持存储包含缺失值的布尔数据(True、False),这对于 bool numpy.ndarray 是不可能的。
|
带有缺失值的布尔(True/False)数据数组。 |
|
布尔数据的扩展类型。 |
工具#
构造函数#
|
组合列表式的 Categorical 对象,并联合类别。 |
|
返回标量或类列表值的类型标签。 |
|
将输入转换为仅 pandas 的 dtype 对象或 numpy 的 dtype 对象。 |
数据类型内省#
|
检查提供的数组或 dtype 是否为实数 dtype。 |
|
检查提供的数组或 dtype 是否为布尔 dtype。 |
|
(已弃用)检查数组状对象或数据类型是否是 Categorical 数据类型。 |
|
检查提供的数组或 dtype 是否为复数 dtype。 |
|
检查提供的数组或 dtype 是否为 datetime64 dtype。 |
|
检查类数组或 dtype 是否为 datetime64 dtype。 |
|
检查提供的数组或 dtype 是否为 datetime64[ns] dtype。 |
|
(已弃用)检查数组状对象或数据类型是否是 DatetimeTZDtype 数据类型。 |
|
检查一个对象是否为 pandas 扩展数组类型。 |
|
检查提供的数组或 dtype 是否为浮点数 dtype。 |
|
(已弃用)检查提供的数组或数据类型是否是 int64 数据类型。 |
|
检查提供的数组或 dtype 是否为整数 dtype。 |
|
(已弃用)检查数组状对象或数据类型是否是 Interval 数据类型。 |
|
检查提供的数组或 dtype 是否为数字 dtype。 |
|
检查数组或 dtype 是否为 object dtype。 |
|
(已弃用)检查数组状对象或数据类型是否是 Period 数据类型。 |
|
检查提供的数组或 dtype 是否为有符号整数 dtype。 |
|
检查提供的数组或 dtype 是否为字符串 dtype。 |
|
检查类数组对象或 dtype 是否为 timedelta64 dtype。 |
|
检查提供的数组或 dtype 是否为 timedelta64[ns] dtype。 |
|
检查提供的数组或 dtype 是否为无符号整数 dtype。 |
|
(已弃用)检查数组状对象是否是 1-D pandas 稀疏数组。 |
可迭代内省#
|
检查对象是否为 dict-like。 |
|
检查该对象是否为类文件对象。 |
|
检查该对象是否为类列表对象。 |
|
检查该对象是否为命名元组。 |
|
检查该对象是否为迭代器。 |
标量自省#
|
如果给定对象是布尔类型,则返回 True。 |
|
如果给定对象是复数类型,则返回 True。 |
|
如果给定对象是浮点数,则返回 True。 |
|
如果 hash(obj) 成功,则返回 True,否则返回 False。 |
|
如果给定对象是整数,则返回 True。 |
|
|
|
检查该对象是否为数字。 |
|
检查该对象是否为正则表达式模式实例。 |
检查该对象是否可以编译为正则表达式模式实例。 |
|
|
如果给定对象为标量,则返回 True。 |