Pandas-2-2-中文文档-二十六-

Pandas 2.2 中文文档(二十六)

原文:pandas.pydata.org/docs/

pandas.Interval.length

原文:pandas.pydata.org/docs/reference/api/pandas.Interval.length.html

Interval.length

返回区间的长度。

另请参阅

Interval.is_empty

表示一个区间是否不包含任何点。

示例

>>> interval = pd.Interval(left=1, right=2, closed='left')
>>> interval
Interval(1, 2, closed='left')
>>> interval.length
1 

pandas.Interval.mid

原文:pandas.pydata.org/docs/reference/api/pandas.Interval.mid.html

Interval.mid

返回区间的中点。

例子

>>> iv = pd.Interval(0, 5)
>>> iv.mid
2.5 

pandas.Interval.open_left

原文:pandas.pydata.org/docs/reference/api/pandas.Interval.open_left.html

Interval.open_left

检查区间左侧是否为开区间。

关于闭区间和开区间的含义,请参阅Interval

返回:

布尔值

如果区间左侧不是闭合的,则为 True。

另请参阅

Interval.open_right

检查区间右侧是否为开区间。

Interval.closed_left

open_left 的布尔反义。

示例

>>> iv = pd.Interval(0, 5, closed='neither')
>>> iv.open_left
True 
>>> iv = pd.Interval(0, 5, closed='both')
>>> iv.open_left
False 

pandas.Interval.open_right

原文:pandas.pydata.org/docs/reference/api/pandas.Interval.open_right.html

Interval.open_right

检查区间右侧是否开放。

关于闭合和开放的含义,请参见Interval

返回:

布尔值

如果区间左侧不闭合,则为 True。

另请参阅

Interval.open_left

检查区间左侧是否开放。

Interval.closed_right

open_right 的布尔值的相反值。

示例

>>> iv = pd.Interval(0, 5, closed='left')
>>> iv.open_right
True 
>>> iv = pd.Interval(0, 5)
>>> iv.open_right
False 

pandas.Interval.overlaps

原文:pandas.pydata.org/docs/reference/api/pandas.Interval.overlaps.html

Interval.overlaps(other)

检查两个区间对象是否重叠。

如果它们共享一个公共点,包括闭合端点,则两个区间重叠。只有一个共同开放端点的区间不重叠。

参数:

otherInterval

用于检查重叠的区间。

返回:

布尔

如果两个区间重叠,则为 True。

另请参阅

IntervalArray.overlaps

IntervalArray 的对应方法。

IntervalIndex.overlaps

IntervalIndex 的对应方法。

示例

>>> i1 = pd.Interval(0, 2)
>>> i2 = pd.Interval(1, 3)
>>> i1.overlaps(i2)
True
>>> i3 = pd.Interval(4, 5)
>>> i1.overlaps(i3)
False 

共享闭合端点的区间重叠:

>>> i4 = pd.Interval(0, 1, closed='both')
>>> i5 = pd.Interval(1, 2, closed='both')
>>> i4.overlaps(i5)
True 

只有一个共同开放端点的区间不重叠:

>>> i6 = pd.Interval(1, 2, closed='neither')
>>> i4.overlaps(i6)
False 

pandas.Interval.right

原文:pandas.pydata.org/docs/reference/api/pandas.Interval.right.html

Interval.right

区间的右边界。

Examples

>>> interval = pd.Interval(left=1, right=2, closed='left')
>>> interval
Interval(1, 2, closed='left')
>>> interval.right
2 

pandas.arrays.IntervalArray

原文:pandas.pydata.org/docs/reference/api/pandas.arrays.IntervalArray.html

class pandas.arrays.IntervalArray(data, closed=None, dtype=None, copy=False, verify_integrity=True)

用于在同一侧关闭的间隔数据的 Pandas 数组。

参数:

dataarray-like (1-dimensional)

包含 Interval 对象的类似数组(ndarray、DateTimeArrayTimeDeltaArray)用于构建 IntervalArray。

closed,默认为 ‘right’

区间是在左侧、右侧、两侧还是无侧闭合。

dtypedtype 或 None,默认为 None

如果为 None,则将推断 dtype。

copybool,默认为 False

复制输入数据。

verify_integritybool,默认为 True

验证 IntervalArray 是否有效。

另请参阅

Index

基本的 pandas 索引类型。

Interval

一个有界的类似切片的区间;IntervalArray 的元素。

interval_range

创建固定频率 IntervalIndex 的函数。

cut

将值分配到离散的区间中。

qcut

根据排名或样本分位数将值分配到相等大小的区间中。

注意

查看更多内容,请参阅用户指南

示例

可以直接从类似于 Interval 对象的数组构建新的 IntervalArray

>>> pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)])
<IntervalArray>
[(0, 1], (1, 5]]
Length: 2, dtype: interval[int64, right] 

也可以使用以下构造方法之一构建:IntervalArray.from_arrays()IntervalArray.from_breaks()IntervalArray.from_tuples()

属性

left 返回 IntervalArray 中每个区间的左端点作为索引。
right 返回 IntervalArray 中每个区间的右端点作为索引。
closed 描述区间的包含侧的字符串。
mid 返回 IntervalArray 中每个区间的中点作为索引。
length 返回一个索引,其中的条目表示每个区间的长度。
is_empty 指示一个区间是否为空,即不包含任何点。
is_non_overlapping_monotonic 返回一个布尔值,指示 IntervalArray 是否是非重叠且单调的。

方法

from_arrays(left, right[, closed, copy, dtype]) 从定义左右边界的两个数组构造。
from_tuples(data[, closed, copy, dtype]) 从元组的类似数组构造一个 IntervalArray。
from_breaks(breaks[, closed, copy, dtype]) 从一个分割数组构造一个 IntervalArray。
contains(other) 逐个元素检查区间是否包含该值。
overlaps(other) 检查逐个元素是否与 IntervalArray 中的值重叠。
set_closed(closed) 返回一个在指定侧关闭的相同的 IntervalArray。
to_tuples([na_tuple]) 返回一个形式为 (left, right) 的元组的 ndarray(如果 self 是 IntervalArray)或 Index(如果 self 是 IntervalIndex)。

pandas.IntervalDtype

原文:pandas.pydata.org/docs/reference/api/pandas.IntervalDtype.html

class pandas.IntervalDtype(subtype=None, closed=None)

一个用于区间数据的 ExtensionDtype。

这不是一个实际的 numpy dtype,而是一个鸭子类型。

参数:

subtypestr, np.dtype

区间边界的 dtype。

示例

>>> pd.IntervalDtype(subtype='int64', closed='both')
interval[int64, both] 

属性

subtype 区间边界的 dtype。

方法

None

pandas.arrays.IntegerArray

原文:pandas.pydata.org/docs/reference/api/pandas.arrays.IntegerArray.html

class pandas.arrays.IntegerArray(values, mask, copy=False)

整数(可选缺失)值的数组。

使用pandas.NA表示缺失值。

警告

IntegerArray 目前处于实验阶段,其 API 或内部实现可能会在不提前通知的情况下更改。

我们用 2 个 numpy 数组表示一个 IntegerArray:

  • data:包含适当数据类型的 numpy 整数数组

  • mask:一个布尔数组,保存数据的掩码,True 表示缺失

要从通用数组输入构建 IntegerArray,请使用pandas.array()和其中一个整数数据类型之一(见示例)。

查看可空整数数据类型以了解更多信息。

参数:

values numpy.ndarray

一个 1 维整数数据类型数组。

mask numpy.ndarray

一个指示缺失值的 1 维布尔数据类型数组。

copy bool,默认为 False

是否复制值和掩码。

返回:

IntegerArray

示例

使用pandas.array()创建一个 IntegerArray。

>>> int_array = pd.array([1, None, 3], dtype=pd.Int32Dtype())
>>> int_array
<IntegerArray>
[1, <NA>, 3]
Length: 3, dtype: Int32 

数据类型的字符串别名也是可用的。它们是大写的。

>>> pd.array([1, None, 3], dtype='Int32')
<IntegerArray>
[1, <NA>, 3]
Length: 3, dtype: Int32 
>>> pd.array([1, None, 3], dtype='UInt16')
<IntegerArray>
[1, <NA>, 3]
Length: 3, dtype: UInt16 

属性

None

方法

None

pandas.Int8Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Int8Dtype.html

class pandas.Int8Dtype

用于 int8 整数数据的 ExtensionDtype。

使用pandas.NA作为其缺失值,而不是numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

方法

pandas.Int16Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Int16Dtype.html

class pandas.Int16Dtype

一个用于 int16 整数数据的 ExtensionDtype。

使用 pandas.NA 作为其缺失值,而不是 numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

方法

pandas.Int32Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Int32Dtype.html

class pandas.Int32Dtype

用于 int32 整数数据的扩展数据类型。

使用 pandas.NA 作为其缺失值,而不是 numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

方法

pandas.Int64Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Int64Dtype.html

class pandas.Int64Dtype

一种适用于 int64 整数数据的扩展数据类型。

使用 pandas.NA 作为其缺失值,而不是 numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

方法

pandas.UInt8Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.UInt8Dtype.html

class pandas.UInt8Dtype

用于 uint8 整数数据的 ExtensionDtype。

使用pandas.NA作为其缺失值,而不是numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

方法

pandas.UInt16Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.UInt16Dtype.html

class pandas.UInt16Dtype

用于 uint16 整数数据的 ExtensionDtype。

使用pandas.NA作为其缺失值,而不是numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

None

方法

None

pandas.UInt32Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.UInt32Dtype.html

class pandas.UInt32Dtype

用于 uint32 整数数据的 ExtensionDtype。

使用pandas.NA作为其缺失值,而不是numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

None

方法

None

pandas.UInt64Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.UInt64Dtype.html

class pandas.UInt64Dtype

用于 uint64 整数数据的 ExtensionDtype。

使用pandas.NA作为其缺失值,而不是numpy.nan

示例

对于 Int8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int8Dtype())
>>> ser.dtype
Int8Dtype() 

对于 Int16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int16Dtype())
>>> ser.dtype
Int16Dtype() 

对于 Int32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int32Dtype())
>>> ser.dtype
Int32Dtype() 

对于 Int64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.Int64Dtype())
>>> ser.dtype
Int64Dtype() 

对于 UInt8Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt8Dtype())
>>> ser.dtype
UInt8Dtype() 

对于 UInt16Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt16Dtype())
>>> ser.dtype
UInt16Dtype() 

对于 UInt32Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt32Dtype())
>>> ser.dtype
UInt32Dtype() 

对于 UInt64Dtype:

>>> ser = pd.Series([2, pd.NA], dtype=pd.UInt64Dtype())
>>> ser.dtype
UInt64Dtype() 

属性

方法

pandas.arrays.FloatingArray

pandas.pydata.org/docs/reference/api/pandas.arrays.FloatingArray.html

class pandas.arrays.FloatingArray(values, mask, copy=False)

浮点(可选缺失)值数组。

警告

FloatingArray 目前处于实验阶段,其 API 或内部实现可能会在没有警告的情况下发生变化。特别是关于 NaN(与 NA 缺失值不同)的行为可能会发生变化。

我们用 2 个 numpy 数组表示一个 FloatingArray:

  • data:包含适当 dtype 的 numpy 浮点数组

  • mask:一个保存数据掩码的布尔数组,True 表示缺失值

要从通用类似数组输入构建 FloatingArray,请使用 pandas.array() 之一的浮点 dtype(请参阅示例)。

更多信息请参阅可空整数数据类型。

参数:

valuesnumpy.ndarray

一个 1 维的浮点数 dtype 数组。

masknumpy.ndarray

一个表示缺失值的 1 维布尔型数组。

copybool,默认为 False

是否复制值和掩码。

返回:

FloatingArray

示例

使用 pandas.array() 创建一个 FloatingArray:

>>> pd.array([0.1, None, 0.3], dtype=pd.Float32Dtype())
<FloatingArray>
[0.1, <NA>, 0.3]
Length: 3, dtype: Float32 

dtype 的字符串别名也是可用的。它们是大写的。

>>> pd.array([0.1, None, 0.3], dtype="Float32")
<FloatingArray>
[0.1, <NA>, 0.3]
Length: 3, dtype: Float32 

属性

None

方法

None

pandas.Float32Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Float32Dtype.html

class pandas.Float32Dtype

用于 float32 数据的 ExtensionDtype。

这种数据类型使用pd.NA作为缺失值指示符。

示例

对于 Float32Dtype:

>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float32Dtype())
>>> ser.dtype
Float32Dtype() 

对于 Float64Dtype:

>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float64Dtype())
>>> ser.dtype
Float64Dtype() 

属性

方法

pandas.Float64Dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Float64Dtype.html

class pandas.Float64Dtype

用于 float64 数据的 ExtensionDtype。

这种数据类型使用pd.NA作为缺失值指示符。

示例

对于 Float32Dtype:

>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float32Dtype())
>>> ser.dtype
Float32Dtype() 

对于 Float64Dtype:

>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float64Dtype())
>>> ser.dtype
Float64Dtype() 

属性

方法

pandas.CategoricalDtype

原文:pandas.pydata.org/docs/reference/api/pandas.CategoricalDtype.html

class pandas.CategoricalDtype(categories=None, ordered=False)

用于具有类别和有序性的分类数据的类型。

参数:

类别序列,可选

必须是唯一的,并且不能包含任何空值。类别存储在索引中,如果提供了索引,则将使用该索引的 dtype。

有序布尔值或 None,默认为 False

是否将此分类视为有序分类。当在组合分类时使用时,可以使用None来保持现有分类的有序值,例如在 astype 等操作中,并且如果没有现有的有序值要保持,则会解析为 False。

另请参阅

分类

以经典的 R / S-plus 风格表示分类变量。

注意

此类对于指定Categorical的类型而独立于值是有用的。更多信息请参见 CategoricalDtype。

示例

>>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True)
>>> pd.Series(['a', 'b', 'a', 'c'], dtype=t)
0      a
1      b
2      a
3    NaN
dtype: category
Categories (2, object): ['b' < 'a'] 

可通过提供空索引来创建具有特定 dtype 的空 CategoricalDtype。如下所示,

>>> pd.CategoricalDtype(pd.DatetimeIndex([])).categories.dtype
dtype('<M8[ns]') 

属性

类别 包含允许的唯一类别的Index
有序 类别是否具有有序关系。

方法

None

pandas.CategoricalDtype.categories

原文:pandas.pydata.org/docs/reference/api/pandas.CategoricalDtype.categories.html

property CategoricalDtype.categories

包含允许的唯一类别的Index

示例

>>> cat_type = pd.CategoricalDtype(categories=['a', 'b'], ordered=True)
>>> cat_type.categories
Index(['a', 'b'], dtype='object') 

pandas.CategoricalDtype.ordered

原文:pandas.pydata.org/docs/reference/api/pandas.CategoricalDtype.ordered.html

property CategoricalDtype.ordered

分类是否具有顺序关系。

示例

>>> cat_type = pd.CategoricalDtype(categories=['a', 'b'], ordered=True)
>>> cat_type.ordered
True 
>>> cat_type = pd.CategoricalDtype(categories=['a', 'b'], ordered=False)
>>> cat_type.ordered
False 

pandas.Categorical

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.html

class pandas.Categorical(values, categories=None, ordered=None, dtype=None, fastpath=_NoDefault.no_default, copy=True)

以经典的 R / S-plus 方式表示分类变量。

分类只能取有限的、通常是固定的可能值(类别)。与统计分类变量相反,分类可能具有顺序,但不可能进行数值运算(加法、除法等)。

所有分类的值都在类别或 np.nan 中。将值分配到类别之外将引发值错误。顺序由类别的顺序而不是值的词法顺序定义。

参数:

类似列表

分类的值。如果给定了类别,则不在类别中的值将被替换为 NaN。

类别索引样式(唯一),可选

此分类的唯一类别。如果未给出,则假定类别是值的唯一值(如果可能排序,则排序,否则按照它们出现的顺序)。

ordered布尔型,默认为 False

此分类是否被视为有序分类。如果为 True,则结果分类将是有序的。有序分类尊重其类别属性(其类别参数,如果提供的话)的顺序,当排序时。

dtypeCategoricalDtype

用于此分类的CategoricalDtype的实例。

引发:

值错误

如果类别不验证。

类型错误

如果明确给出了ordered=True但没有类别且值不可排序。

参见

CategoricalDtype

用于分类数据的类型。

CategoricalIndex

具有底层Categorical的索引。

注意

有关更多信息,请参阅用户指南

示例

>>> pd.Categorical([1, 2, 3, 1, 2, 3])
[1, 2, 3, 1, 2, 3]
Categories (3, int64): [1, 2, 3] 
>>> pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'])
['a', 'b', 'c', 'a', 'b', 'c']
Categories (3, object): ['a', 'b', 'c'] 

丢失值不包括在类别中。

>>> c = pd.Categorical([1, 2, 3, 1, 2, 3, np.nan])
>>> c
[1, 2, 3, 1, 2, 3, NaN]
Categories (3, int64): [1, 2, 3] 

然而,它们的存在在代码属性中由代码-1 表示。

>>> c.codes
array([ 0,  1,  2,  0,  1,  2, -1], dtype=int8) 

有序分类可以根据类别的自定义顺序进行排序,并且可以具有最小值和最大值。

>>> c = pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'], ordered=True,
...                    categories=['c', 'b', 'a'])
>>> c
['a', 'b', 'c', 'a', 'b', 'c']
Categories (3, object): ['c' < 'b' < 'a']
>>> c.min()
'c' 

属性

categories 此分类的类别。
codes 此分类索引的类别代码。
ordered 类别是否具有有序关系。
dtype 此实例的CategoricalDtype

方法

from_codes(codes[, categories, ordered, ...]) 从编码和类别或 dtype 创建一个分类类型。
__array__([dtype, copy]) numpy 数组接口。

pandas.Categorical.from_codes

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.from_codes.html

classmethod Categorical.from_codes(codes, categories=None, ordered=None, dtype=None, validate=True)

从代码和类别或 dtype 创建一个分类类型。

如果您已经拥有代码和类别/dtype,则此构造函数很有用,因此不需要(计算密集型)因子化步骤,该步骤通常在构造函数中完成。

如果您的数据不遵循此约定,请使用普通的构造函数。

参数:

代码int 类型的数组

一个整数数组,其中每个整数指向 categories 或 dtype.categories 中的一个类别,或者对于 NaN 为-1。

类别类似索引,可选

分类的类别。项目需要是唯一的。如果此处未给出类别,则它们必须在 dtype 中提供。

ordered布尔型,可选

无论此分类是否被视为有序分类。如果未在此处或 dtype 中给出,则生成的分类将是无序的。

dtypeCategoricalDtype 或“category”,可选

如果CategoricalDtype不能与类别或有序一起使用。

验证布尔型,默认为 True

如果为 True,则验证代码是否对 dtype 有效。如果为 False,则不验证代码是否有效。小心跳过验证,因为无效的代码可能导致严重问题,如段错误。

新版本 2.1.0 中新增。

返回:

分类

示例

>>> dtype = pd.CategoricalDtype(['a', 'b'], ordered=True)
>>> pd.Categorical.from_codes(codes=[0, 1, 0, 1], dtype=dtype)
['a', 'b', 'a', 'b']
Categories (2, object): ['a' < 'b'] 

pandas.Categorical.dtype

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.dtype.html

property Categorical.dtype

此实例的CategoricalDtype

示例

>>> cat = pd.Categorical(['a', 'b'], ordered=True)
>>> cat
['a', 'b']
Categories (2, object): ['a' < 'b']
>>> cat.dtype
CategoricalDtype(categories=['a', 'b'], ordered=True, categories_dtype=object) 

pandas.Categorical.categories

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.categories.html

property Categorical.categories

此分类的类别。

设置将新值分配给每个类别(实质上是对每个单独类别进行重命名)。

分配的值必须是类似列表的对象。所有项必须是唯一的,新类别中的项数必须与旧类别中的项数相同。

引发:

ValueError

如果新类别无法验证为类别,或者新类别的数量与旧类别的数量不相等

另请参阅

rename_categories

重命名类别。

reorder_categories

重新排序类别。

add_categories

添加新的类别。

remove_categories

删除指定的类别。

remove_unused_categories

删除未使用的类别。

set_categories

将类别设置为指定的类别。

示例

对于pandas.Series

>>> ser = pd.Series(['a', 'b', 'c', 'a'], dtype='category')
>>> ser.cat.categories
Index(['a', 'b', 'c'], dtype='object') 
>>> raw_cat = pd.Categorical(['a', 'b', 'c', 'a'], categories=['b', 'c', 'd'])
>>> ser = pd.Series(raw_cat)
>>> ser.cat.categories
Index(['b', 'c', 'd'], dtype='object') 

对于pandas.Categorical

>>> cat = pd.Categorical(['a', 'b'], ordered=True)
>>> cat.categories
Index(['a', 'b'], dtype='object') 

对于pandas.CategoricalIndex

>>> ci = pd.CategoricalIndex(['a', 'c', 'b', 'a', 'c', 'b'])
>>> ci.categories
Index(['a', 'b', 'c'], dtype='object') 
>>> ci = pd.CategoricalIndex(['a', 'c'], categories=['c', 'b', 'a'])
>>> ci.categories
Index(['c', 'b', 'a'], dtype='object') 

pandas.Categorical.ordered

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.ordered.html

property Categorical.ordered

类别是否具有有序关系。

示例

对于pandas.Series

>>> ser = pd.Series(['a', 'b', 'c', 'a'], dtype='category')
>>> ser.cat.ordered
False 
>>> raw_cat = pd.Categorical(['a', 'b', 'c', 'a'], ordered=True)
>>> ser = pd.Series(raw_cat)
>>> ser.cat.ordered
True 

对于pandas.Categorical

>>> cat = pd.Categorical(['a', 'b'], ordered=True)
>>> cat.ordered
True 
>>> cat = pd.Categorical(['a', 'b'], ordered=False)
>>> cat.ordered
False 

对于pandas.CategoricalIndex

>>> ci = pd.CategoricalIndex(['a', 'b'], ordered=True)
>>> ci.ordered
True 
>>> ci = pd.CategoricalIndex(['a', 'b'], ordered=False)
>>> ci.ordered
False 

pandas.Categorical.codes

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.codes.html

property Categorical.codes

这个分类索引的类别代码。

代码是一个整数数组,其中整数是实际值在类别数组中的位置。

没有设置器,使用其他分类方法和正常的项目设置器来更改分类中的值。

返回:

ndarray[int]

codes数组的不可写视图。

示例

对于pandas.Categorical

>>> cat = pd.Categorical(['a', 'b'], ordered=True)
>>> cat.codes
array([0, 1], dtype=int8) 

对于pandas.CategoricalIndex

>>> ci = pd.CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'])
>>> ci.codes
array([0, 1, 2, 0, 1, 2], dtype=int8) 
>>> ci = pd.CategoricalIndex(['a', 'c'], categories=['c', 'b', 'a'])
>>> ci.codes
array([2, 0], dtype=int8) 

pandas.Categorical.__array__

原文:pandas.pydata.org/docs/reference/api/pandas.Categorical.__array__.html

Categorical.__array__(dtype=None, copy=None)

numpy 数组接口。

返回:

numpy.array

一个 numpy 数组,可以是指定的数据类型,或者如果 dtype==None(默认),则与 categorical.categories.dtype 相同的数据类型。

示例

>>> cat = pd.Categorical(['a', 'b'], ordered=True) 

下面调用了cat.__array__

>>> np.asarray(cat)
array(['a', 'b'], dtype=object) 

pandas.arrays.SparseArray

原文:pandas.pydata.org/docs/reference/api/pandas.arrays.SparseArray.html

class pandas.arrays.SparseArray(data, sparse_index=None, fill_value=None, kind='integer', dtype=None, copy=False)

用于存储稀疏数据的 ExtensionArray。

参数:

数据类似数组或标量

要存储在 SparseArray 中的值的密集数组。这可能包含 fill_value。

稀疏索引SparseIndex,可选

填充值标量,可选

数据中的 fill_value 元素不会存储在 SparseArray 中。为了节省内存,这应该是数据中最常见的值。默认情况下,fill_value 取决于数据的 dtype:

数据.dtype na_value
浮点数 np.nan
整数 0
布尔型 False
datetime64 pd.NaT
timedelta64 pd.NaT

填充值可能以三种方式指定。按优先顺序,它们是

  1. fill_value 参数

  2. 如果 fill_value 为 None 而且 dtype 是 SparseDtype,则为 dtype.fill_value

  3. 如果 fill_value 为 None 而且 dtype 不是 SparseDtype 且数据是 SparseArray,则为 data.dtype.fill_value

类型字符串

可以是 ‘integer’ 或 ‘block’,默认为 ‘integer’。稀疏位置的存储类型。

  • ‘block’: 为每个连续的稀疏值 范围 存储一个块和块长度。当稀疏数据倾向于聚集在一起,并且大区域之间有大量的 fill-value 值时,这是最好的选择。

  • ‘integer’: 使用整数存储每个稀疏值的位置。

数据类型np.dtype 或 SparseDtype,可选

用于 SparseArray 的数据类型。对于 numpy 数据类型,这确定了 self.sp_values 的数据类型。对于 SparseDtype,这确定了 self.sp_valuesself.fill_value 的数据类型。

复制布尔型,默认为 False

是否显式复制传入的数据数组。

示例

>>> from pandas.arrays import SparseArray
>>> arr = SparseArray([0, 0, 1, 2])
>>> arr
[0, 0, 1, 2]
Fill: 0
IntIndex
Indices: array([2, 3], dtype=int32) 

属性

方法

pandas.SparseDtype

原文:pandas.pydata.org/docs/reference/api/pandas.SparseDtype.html

class pandas.SparseDtype(dtype=<class 'numpy.float64'>, fill_value=None)

存储在SparseArray中的数据的 Dtype。

此 dtype 实现了 pandas ExtensionDtype 接口。

参数:

dtypestr,ExtensionDtype,numpy.dtype,类型,默认 numpy.float64

存储非填充值的底层数组的 dtype。

fill_value标量,可选

稀疏数组中未存储的标量值。默认情况下,这取决于 dtype。

dtype na_value
float np.nan
int 0
bool False
datetime64 pd.NaT
timedelta64 pd.NaT

默认值可以通过指定 fill_value 进行覆盖。

示例

>>> ser = pd.Series([1, 0, 0], dtype=pd.SparseDtype(dtype=int, fill_value=0))
>>> ser
0    1
1    0
2    0
dtype: Sparse[int64, 0]
>>> ser.sparse.density
0.3333333333333333 

属性

None

方法

None

pandas.arrays.StringArray

原文:pandas.pydata.org/docs/reference/api/pandas.arrays.StringArray.html

class pandas.arrays.StringArray(values, copy=False)

用于字符串数据的扩展数组。

警告

StringArray 被视为实验性功能。实现和部分 API 可能在未提前警告的情况下发生变化。

参数:

valuesarray-like

数据数组。

警告

目前,此处期望一个对象类型的 ndarray,其中元素是 Python 字符串或 nan 类型(Nonenp.nanNA)。此规则可能在未来发生变化而不提前警告。使用 pandas.array() 并指定 dtype="string" 可以稳定地从任何序列创建 StringArray。

从版本 1.5.0 起更改:StringArray 现在还接受包含 nan 类型(Nonenp.nan)的数组类型作为 values 参数,除了字符串和 pandas.NA

copybool,默认为 False

是否复制数据数组。

另请参阅

pandas.array()

创建 StringArray 的推荐函数。

Series.str

由 StringArray 支持的 Series 上提供了字符串方法。

注释

StringArray 对比方法返回一个布尔数组。

示例

>>> pd.array(['This is', 'some text', None, 'data.'], dtype="string")
<StringArray>
['This is', 'some text', <NA>, 'data.']
Length: 4, dtype: string 

与使用 dtype="object" 实例化的数组不同,StringArray 将值转换为字符串。

>>> pd.array(['1', 1], dtype="object")
<NumpyExtensionArray>
['1', 1]
Length: 2, dtype: object
>>> pd.array(['1', 1], dtype="string")
<StringArray>
['1', '1']
Length: 2, dtype: string 

但是,直接使用非字符串实例化 StringArrays 将引发错误。

对比方法中,StringArray 返回一个 pandas.BooleanArray

>>> pd.array(["a", None, "c"], dtype="string") == "a"
<BooleanArray>
[True, <NA>, False]
Length: 3, dtype: boolean 

属性

None

方法

None

pandas.arrays.ArrowStringArray

原文:pandas.pydata.org/docs/reference/api/pandas.arrays.ArrowStringArray.html

class pandas.arrays.ArrowStringArray(values)

用于在 pyarrow.ChunkedArray 中存储字符串数据的扩展数组。

警告

ArrowStringArray 被视为实验性功能。实现和部分 API 可能会在没有警告的情况下发生变化。

参数:

valuespyarrow.Array 或 pyarrow.ChunkedArray

数据数组。

另请参阅

pandas.array()

创建 ArrowStringArray 的推荐函数。

Series.str

字符串方法可用于由 ArrowStringArray 支持的 Series。

注意事项

ArrowStringArray 返回一个 BooleanArray 用于比较方法。

示例

>>> pd.array(['This is', 'some text', None, 'data.'], dtype="string[pyarrow]")
<ArrowStringArray>
['This is', 'some text', <NA>, 'data.']
Length: 4, dtype: string 

属性

方法

pandas.StringDtype

原文:pandas.pydata.org/docs/reference/api/pandas.StringDtype.html

class pandas.StringDtype(storage=None)

字符串数据的扩展 dtype。

警告

StringDtype 被视为实验性的。实现和部分 API 可能会在没有警告的情况下更改。

参数:

storage,可选

如果未提供,则使用pd.options.mode.string_storage的值。

示例

>>> pd.StringDtype()
string[python] 
>>> pd.StringDtype(storage="pyarrow")
string[pyarrow] 

属性

方法

pandas.arrays.BooleanArray

原文:pandas.pydata.org/docs/reference/api/pandas.arrays.BooleanArray.html

class pandas.arrays.BooleanArray(values, mask, copy=False)

带有缺失值的布尔(True/False)数据数组。

这是用于布尔数据的 pandas 扩展数组,在底层由 2 个 numpy 数组表示:一个带有数据的布尔数组和一个带有掩码的布尔数组(True 表示缺失)。

BooleanArray 实现 Kleene 逻辑(有时称为三值逻辑)用于逻辑操作。更多信息请参见 Kleene 逻辑操作。

要从通用类似数组的输入构造一个 BooleanArray,请使用 pandas.array() 指定 dtype="boolean"(请参见下面的示例)。

警告

BooleanArray 被视为实验性质。实现和部分 API 可能会在不经警告的情况下更改。

参数:

valuesnumpy.ndarray

一个带有数据的 1 维布尔类型数组。

masknumpy.ndarray

一个 1 维布尔类型数组,指示缺失值(True 表示缺失)。

copybool,默认为 False

是否复制值和掩码数组。

返回:

BooleanArray

示例

使用 pandas.array() 创建一个 BooleanArray:

>>> pd.array([True, False, None], dtype="boolean")
<BooleanArray>
[True, False, <NA>]
Length: 3, dtype: boolean 

属性

None

方法

None

pandas.BooleanDtype

原文:pandas.pydata.org/docs/reference/api/pandas.BooleanDtype.html

class pandas.BooleanDtype

用于布尔数据的扩展数据类型。

警告

BooleanDtype 被视为实验性功能。实现和部分 API 可能会在没有警告的情况下更改。

示例

>>> pd.BooleanDtype()
BooleanDtype 

属性

方法

pandas.api.types.union_categoricals

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.union_categoricals.html

pandas.api.types.union_categoricals(to_union, sort_categories=False, ignore_order=False)

组合类似 Categorical 的列表,合并类别。

所有类别必须具有相同的 dtype。

参数:

to_union类似列表

具有 dtype=’category’的 Categorical、CategoricalIndex 或 Series。

sort_categories布尔值,默认为 False

如果为 true,则结果类别将被 lexsorted,否则它们将按照它们在数据中出现的顺序排序。

ignore_order布尔值,默认为 False

如果为 true,则将忽略 Categoricals 的有序属性。结果是无序的分类。

返回:

Categorical

引发:

TypeError

  • 所有输入的 dtype 都不相同。

  • 所有输入的有序属性不相同

  • 所有输入都被排序,而它们的类别不相同

  • sort_categories=True 且 Categoricals 被排序

ValueError

传递的 Categoricals 列表为空

注意事项

要了解更多关于类别的信息,请参见链接

示例

如果要组合不一定具有相同类别的分类变量,union_categoricals 将组合类别变量的列表。新类别将是正在组合的类别的并集。

>>> a = pd.Categorical(["b", "c"])
>>> b = pd.Categorical(["a", "b"])
>>> pd.api.types.union_categoricals([a, b])
['b', 'c', 'a', 'b']
Categories (3, object): ['b', 'c', 'a'] 

默认情况下,结果类别将按照数据中类别的出现顺序排序。如果希望类别被 lexsorted,使用 sort_categories=True 参数。

>>> pd.api.types.union_categoricals([a, b], sort_categories=True)
['b', 'c', 'a', 'b']
Categories (3, object): ['a', 'b', 'c'] 

union_categoricals 还适用于合并具有相同类别和顺序信息的两个分类变量的情况(例如,您也可以附加它们)。

>>> a = pd.Categorical(["a", "b"], ordered=True)
>>> b = pd.Categorical(["a", "b", "a"], ordered=True)
>>> pd.api.types.union_categoricals([a, b])
['a', 'b', 'a', 'b', 'a']
Categories (2, object): ['a' < 'b'] 

引发 TypeError,因为类别是有序的,而且不相同。

>>> a = pd.Categorical(["a", "b"], ordered=True)
>>> b = pd.Categorical(["a", "b", "c"], ordered=True)
>>> pd.api.types.union_categoricals([a, b])
Traceback (most recent call last):
  ...
TypeError: to union ordered Categoricals, all categories must be the same 

具有不同类别或排序的有序分类可以使用 ignore_ordered=True 参数组合。

>>> a = pd.Categorical(["a", "b", "c"], ordered=True)
>>> b = pd.Categorical(["c", "b", "a"], ordered=True)
>>> pd.api.types.union_categoricals([a, b], ignore_order=True)
['a', 'b', 'c', 'c', 'b', 'a']
Categories (3, object): ['a', 'b', 'c'] 

union_categoricals 还适用于 CategoricalIndex 或包含分类数据的 Series,但请注意,结果数组将始终是普通的 Categorical。

>>> a = pd.Series(["b", "c"], dtype='category')
>>> b = pd.Series(["a", "b"], dtype='category')
>>> pd.api.types.union_categoricals([a, b])
['b', 'c', 'a', 'b']
Categories (3, object): ['b', 'c', 'a'] 

pandas.api.types.infer_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.infer_dtype.html

pandas.api.types.infer_dtype(value, skipna=True)

返回标量或类似列表的值的类型的字符串标签。

参数:

标量,列表,ndarray 或 pandas 类型

skipna布尔值,默认为 True

在推断类型时忽略 NaN 值。

返回:

字符串

描述输入数据的常见类型。

结果可能包括:

  • 字符串

  • 字节

  • 浮点数

  • 整数

  • 混合整数

  • 混合整数浮点数

  • 十进制

  • 复数

  • 分类的

  • 布尔值

  • 日期时间 64

  • 日期时间

  • 日期

  • 时间增量 64

  • 时间增量

  • 时间

  • 期间

  • 混合

  • 未知数组

引发:

类型错误

如果类似于 ndarray 但无法推断 dtype

笔记

  • ‘mixed’是一个通用术语,用于描述其他未特殊化的内容

  • ‘mixed-integer-float’是浮点数和整数

  • ‘mixed-integer’是整数与非整数混合

  • ‘unknown-array’是一个通用术语,用于描述数组(具有 dtype 属性),但对于 pandas 来说具有未知 dtype(例如外部扩展数组)

示例

>>> from pandas.api.types import infer_dtype
>>> infer_dtype(['foo', 'bar'])
'string' 
>>> infer_dtype(['a', np.nan, 'b'], skipna=True)
'string' 
>>> infer_dtype(['a', np.nan, 'b'], skipna=False)
'mixed' 
>>> infer_dtype([b'foo', b'bar'])
'bytes' 
>>> infer_dtype([1, 2, 3])
'integer' 
>>> infer_dtype([1, 2, 3.5])
'mixed-integer-float' 
>>> infer_dtype([1.0, 2.0, 3.5])
'floating' 
>>> infer_dtype(['a', 1])
'mixed-integer' 
>>> from decimal import Decimal
>>> infer_dtype([Decimal(1), Decimal(2.0)])
'decimal' 
>>> infer_dtype([True, False])
'boolean' 
>>> infer_dtype([True, False, np.nan])
'boolean' 
>>> infer_dtype([pd.Timestamp('20130101')])
'datetime' 
>>> import datetime
>>> infer_dtype([datetime.date(2013, 1, 1)])
'date' 
>>> infer_dtype([np.datetime64('2013-01-01')])
'datetime64' 
>>> infer_dtype([datetime.timedelta(0, 1, 1)])
'timedelta' 
>>> infer_dtype(pd.Series(list('aabc')).astype('category'))
'categorical' 

pandas.api.types.pandas_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.pandas_dtype.html

pandas.api.types.pandas_dtype(dtype)

将输入转换为仅限于 pandas 的 dtype 对象或 numpy 的 dtype 对象。

参数:

dtype需要被转换的对象

返回:

np.dtype 或者是 pandas 的 dtype

引发:

如果不是 dtype,则会引发 TypeError

示例

>>> pd.api.types.pandas_dtype(int)
dtype('int64') 

pandas.api.types.is_any_real_numeric_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_any_real_numeric_dtype.html

pandas.api.types.is_any_real_numeric_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为实数数据类型。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回值:

布尔值

数组或数据类型是否为实数数据类型。

示例

>>> from pandas.api.types import is_any_real_numeric_dtype
>>> is_any_real_numeric_dtype(int)
True
>>> is_any_real_numeric_dtype(float)
True
>>> is_any_real_numeric_dtype(object)
False
>>> is_any_real_numeric_dtype(str)
False
>>> is_any_real_numeric_dtype(complex(1, 2))
False
>>> is_any_real_numeric_dtype(bool)
False 

pandas.api.types.is_bool_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_bool_dtype.html

pandas.api.types.is_bool_dtype(arr_or_dtype)

检查所提供的数组或数据类型是否为布尔类型。

参数:

arr_or_dtype 类似数组或数据类型

要检查的数组或数据类型。

返回:

布尔类型

数组或数据类型是否为布尔类型。

注意事项

_is_boolean 属性设置为 True 时,ExtensionArray 被视为布尔类型。

示例

>>> from pandas.api.types import is_bool_dtype
>>> is_bool_dtype(str)
False
>>> is_bool_dtype(int)
False
>>> is_bool_dtype(bool)
True
>>> is_bool_dtype(np.bool_)
True
>>> is_bool_dtype(np.array(['a', 'b']))
False
>>> is_bool_dtype(pd.Series([1, 2]))
False
>>> is_bool_dtype(np.array([True, False]))
True
>>> is_bool_dtype(pd.Categorical([True, False]))
True
>>> is_bool_dtype(pd.arrays.SparseArray([True, False]))
True 

pandas.api.types.is_categorical_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_categorical_dtype.html

pandas.api.types.is_categorical_dtype(arr_or_dtype)

检查类似数组或 dtype 是否为分类 dtype。

自版本 2.2.0 起已弃用:请改用isinstance(dtype, pd.CategoricalDtype)

参数:

arr_or_dtype类似数组或 dtype

要检查的类似数组或 dtype。

返回:

布尔值

类似数组或 dtype 是否为分类 dtype。

示例

>>> from pandas.api.types import is_categorical_dtype
>>> from pandas import CategoricalDtype
>>> is_categorical_dtype(object)
False
>>> is_categorical_dtype(CategoricalDtype())
True
>>> is_categorical_dtype([1, 2, 3])
False
>>> is_categorical_dtype(pd.Categorical([1, 2, 3]))
True
>>> is_categorical_dtype(pd.CategoricalIndex([1, 2, 3]))
True 

pandas.api.types.is_complex_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_complex_dtype.html

pandas.api.types.is_complex_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为复数数据类型。

参数:

arr_or_dtype数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为复数数据类型。

示例

>>> from pandas.api.types import is_complex_dtype
>>> is_complex_dtype(str)
False
>>> is_complex_dtype(int)
False
>>> is_complex_dtype(np.complex128)
True
>>> is_complex_dtype(np.array(['a', 'b']))
False
>>> is_complex_dtype(pd.Series([1, 2]))
False
>>> is_complex_dtype(np.array([1 + 1j, 5]))
True 

pandas.api.types.is_datetime64_any_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_datetime64_any_dtype.html

pandas.api.types.is_datetime64_any_dtype(arr_or_dtype)

检查提供的数组或数据类型是否是 datetime64 数据类型。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

是否数组或数据类型是 datetime64 数据类型。

示例

>>> from pandas.api.types import is_datetime64_any_dtype
>>> from pandas.core.dtypes.dtypes import DatetimeTZDtype
>>> is_datetime64_any_dtype(str)
False
>>> is_datetime64_any_dtype(int)
False
>>> is_datetime64_any_dtype(np.datetime64)  # can be tz-naive
True
>>> is_datetime64_any_dtype(DatetimeTZDtype("ns", "US/Eastern"))
True
>>> is_datetime64_any_dtype(np.array(['a', 'b']))
False
>>> is_datetime64_any_dtype(np.array([1, 2]))
False
>>> is_datetime64_any_dtype(np.array([], dtype="datetime64[ns]"))
True
>>> is_datetime64_any_dtype(pd.DatetimeIndex([1, 2, 3], dtype="datetime64[ns]"))
True 

pandas.api.types.is_datetime64_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_datetime64_dtype.html

pandas.api.types.is_datetime64_dtype(arr_or_dtype)

检查数组或数据类型是否为 datetime64 数据类型。

参数:

arr_or_dtypearray-like 或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为 datetime64 数据类型。

示例

>>> from pandas.api.types import is_datetime64_dtype
>>> is_datetime64_dtype(object)
False
>>> is_datetime64_dtype(np.datetime64)
True
>>> is_datetime64_dtype(np.array([], dtype=int))
False
>>> is_datetime64_dtype(np.array([], dtype=np.datetime64))
True
>>> is_datetime64_dtype([1, 2, 3])
False 

pandas.api.types.is_datetime64_ns_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_datetime64_ns_dtype.html

pandas.api.types.is_datetime64_ns_dtype(arr_or_dtype)

检查所提供的数组或数据类型是否为 datetime64[ns]数据类型。

参数:

arr_or_dtypearray-like 或 数据类型

要检查的数组或数据类型。

返回值:

bool

数组或数据类型是否为 datetime64[ns]数据类型。

示例

>>> from pandas.api.types import is_datetime64_ns_dtype
>>> from pandas.core.dtypes.dtypes import DatetimeTZDtype
>>> is_datetime64_ns_dtype(str)
False
>>> is_datetime64_ns_dtype(int)
False
>>> is_datetime64_ns_dtype(np.datetime64)  # no unit
False
>>> is_datetime64_ns_dtype(DatetimeTZDtype("ns", "US/Eastern"))
True
>>> is_datetime64_ns_dtype(np.array(['a', 'b']))
False
>>> is_datetime64_ns_dtype(np.array([1, 2]))
False
>>> is_datetime64_ns_dtype(np.array([], dtype="datetime64"))  # no unit
False
>>> is_datetime64_ns_dtype(np.array([], dtype="datetime64[ps]"))  # wrong unit
False
>>> is_datetime64_ns_dtype(pd.DatetimeIndex([1, 2, 3], dtype="datetime64[ns]"))
True 

pandas.api.types.is_datetime64tz_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_datetime64tz_dtype.html

pandas.api.types.is_datetime64tz_dtype(arr_or_dtype)

检查数组样式或 dtype 是否为 DatetimeTZDtype 类型。

自 2.1.0 版本起已弃用:请改用 isinstance(dtype, pd.DatetimeTZDtype)。

参数:

arr_or_dtype 数组样式或 dtype

要检查的数组样式或 dtype。

返回值:

布尔值

数组样式或 dtype 是否为 DatetimeTZDtype 类型。

示例

>>> from pandas.api.types import is_datetime64tz_dtype
>>> is_datetime64tz_dtype(object)
False
>>> is_datetime64tz_dtype([1, 2, 3])
False
>>> is_datetime64tz_dtype(pd.DatetimeIndex([1, 2, 3]))  # tz-naive
False
>>> is_datetime64tz_dtype(pd.DatetimeIndex([1, 2, 3], tz="US/Eastern"))
True 
>>> from pandas.core.dtypes.dtypes import DatetimeTZDtype
>>> dtype = DatetimeTZDtype("ns", tz="US/Eastern")
>>> s = pd.Series([], dtype=dtype)
>>> is_datetime64tz_dtype(dtype)
True
>>> is_datetime64tz_dtype(s)
True 

pandas.api.types.is_extension_array_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_extension_array_dtype.html

pandas.api.types.is_extension_array_dtype(arr_or_dtype)

检查对象是否是 pandas 扩展数组类型。

更多信息请参见使用指南。

参数:

arr_or_dtype 对象

对于类似数组的输入,将提取.dtype属性。

返回:

bool

是否 arr_or_dtype 是扩展数组类型。

注意事项

这会检查对象是否实现了 pandas 扩展数组接口。在 pandas 中,这包括:

  • Categorical

  • 稀疏

  • Interval

  • Period

  • DatetimeArray

  • TimedeltaArray

第三方库也可能实现满足此接口的数组或类型。

示例

>>> from pandas.api.types import is_extension_array_dtype
>>> arr = pd.Categorical(['a', 'b'])
>>> is_extension_array_dtype(arr)
True
>>> is_extension_array_dtype(arr.dtype)
True 
>>> arr = np.array(['a', 'b'])
>>> is_extension_array_dtype(arr.dtype)
False 

pandas.api.types.is_float_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_float_dtype.html

pandas.api.types.is_float_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为浮点数据类型。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回值:

布尔值

数组或数据类型是否为浮点数据类型。

示例

>>> from pandas.api.types import is_float_dtype
>>> is_float_dtype(str)
False
>>> is_float_dtype(int)
False
>>> is_float_dtype(float)
True
>>> is_float_dtype(np.array(['a', 'b']))
False
>>> is_float_dtype(pd.Series([1, 2]))
False
>>> is_float_dtype(pd.Index([1, 2.]))
True 

pandas.api.types.is_int64_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_int64_dtype.html

pandas.api.types.is_int64_dtype(arr_or_dtype)

检查提供的数组或 dtype 是否为 int64 类型。

自 2.1.0 版本起已弃用:is_int64_dtype 已弃用,并将在将来的版本中移除。请改用 dtype == np.int64。

参数:

arr_or_dtype 数组样式或 dtype

要检查的数组或 dtype。

返回值:

布尔值

提供的数组或 dtype 是否为 int64 类型。

注意事项

根据系统架构,如果操作系统使用 64 位整数,则 is_int64_dtype(int) 的返回值将为 True;如果操作系统使用 32 位整数,则返回值为 False。

示例

>>> from pandas.api.types import is_int64_dtype
>>> is_int64_dtype(str)  
False
>>> is_int64_dtype(np.int32)  
False
>>> is_int64_dtype(np.int64)  
True
>>> is_int64_dtype('int8')  
False
>>> is_int64_dtype('Int8')  
False
>>> is_int64_dtype(pd.Int64Dtype)  
True
>>> is_int64_dtype(float)  
False
>>> is_int64_dtype(np.uint64)  # unsigned 
False
>>> is_int64_dtype(np.array(['a', 'b']))  
False
>>> is_int64_dtype(np.array([1, 2], dtype=np.int64))  
True
>>> is_int64_dtype(pd.Index([1, 2.]))  # float 
False
>>> is_int64_dtype(np.array([1, 2], dtype=np.uint32))  # unsigned 
False 

pandas.api.types.is_integer_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_integer_dtype.html

pandas.api.types.is_integer_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为整数数据类型。

与 is_any_int_dtype 不同,timedelta64 实例将返回 False。

可空整数数据类型(例如 pandas.Int64Dtype)也被此函数视为整数。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为整数数据类型而不是 timedelta64 的实例。

示例

>>> from pandas.api.types import is_integer_dtype
>>> is_integer_dtype(str)
False
>>> is_integer_dtype(int)
True
>>> is_integer_dtype(float)
False
>>> is_integer_dtype(np.uint64)
True
>>> is_integer_dtype('int8')
True
>>> is_integer_dtype('Int8')
True
>>> is_integer_dtype(pd.Int8Dtype)
True
>>> is_integer_dtype(np.datetime64)
False
>>> is_integer_dtype(np.timedelta64)
False
>>> is_integer_dtype(np.array(['a', 'b']))
False
>>> is_integer_dtype(pd.Series([1, 2]))
True
>>> is_integer_dtype(np.array([], dtype=np.timedelta64))
False
>>> is_integer_dtype(pd.Index([1, 2.]))  # float
False 

pandas.api.types.is_interval_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_interval_dtype.html

pandas.api.types.is_interval_dtype(arr_or_dtype)

检查数组或数据类型是否为区间数据类型。

自版本 2.2.0 起已弃用:请改用 isinstance(dtype, pd.IntervalDtype)。

参数:

arr_or_dtype数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为区间数据类型。

示例

>>> from pandas.core.dtypes.common import is_interval_dtype
>>> is_interval_dtype(object)
False
>>> is_interval_dtype(pd.IntervalDtype())
True
>>> is_interval_dtype([1, 2, 3])
False
>>>
>>> interval = pd.Interval(1, 2, closed="right")
>>> is_interval_dtype(interval)
False
>>> is_interval_dtype(pd.IntervalIndex([interval]))
True 

pandas.api.types.is_numeric_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_numeric_dtype.html

pandas.api.types.is_numeric_dtype(arr_or_dtype)

检查所提供的数组或数据类型是否为数值数据类型。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

是否数组或数据类型是数值数据类型。

示例

>>> from pandas.api.types import is_numeric_dtype
>>> is_numeric_dtype(str)
False
>>> is_numeric_dtype(int)
True
>>> is_numeric_dtype(float)
True
>>> is_numeric_dtype(np.uint64)
True
>>> is_numeric_dtype(np.datetime64)
False
>>> is_numeric_dtype(np.timedelta64)
False
>>> is_numeric_dtype(np.array(['a', 'b']))
False
>>> is_numeric_dtype(pd.Series([1, 2]))
True
>>> is_numeric_dtype(pd.Index([1, 2.]))
True
>>> is_numeric_dtype(np.array([], dtype=np.timedelta64))
False 

pandas.api.types.is_object_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_object_dtype.html

pandas.api.types.is_object_dtype(arr_or_dtype)

检查类似数组或数据类型是否为对象数据类型。

参数:

arr_or_dtype类似数组或数据类型

要检查的类似数组或数据类型。

返回:

布尔值

类似数组或数据类型是否为对象数据类型。

示例

>>> from pandas.api.types import is_object_dtype
>>> is_object_dtype(object)
True
>>> is_object_dtype(int)
False
>>> is_object_dtype(np.array([], dtype=object))
True
>>> is_object_dtype(np.array([], dtype=int))
False
>>> is_object_dtype([1, 2, 3])
False 

pandas.api.types.is_period_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_period_dtype.html

pandas.api.types.is_period_dtype(arr_or_dtype)

检查数组样式或数据类型是否为 Period 数据类型。

从版本 2.2.0 开始已弃用:请改用 isinstance(dtype, pd.Period)

参数:

arr_or_dtype:数组样式或数据类型

要检查的数组样式或数据类型。

返回值:

布尔值

数组样式或数据类型是否为 Period 数据类型。

示例

>>> from pandas.core.dtypes.common import is_period_dtype
>>> is_period_dtype(object)
False
>>> is_period_dtype(pd.PeriodDtype(freq="D"))
True
>>> is_period_dtype([1, 2, 3])
False
>>> is_period_dtype(pd.Period("2017-01-01"))
False
>>> is_period_dtype(pd.PeriodIndex([], freq="Y"))
True 

pandas.api.types.is_signed_integer_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_signed_integer_dtype.html

pandas.api.types.is_signed_integer_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为有符号整数数据类型。

与 is_any_int_dtype 不同,timedelta64 实例将返回 False。

可空整数数据类型(例如 pandas.Int64Dtype)也被此函数视为整数。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回值:

布尔值

检查数组或数据类型是否为有符号整数数据类型而不是 timedelta64 的实例。

示例

>>> from pandas.core.dtypes.common import is_signed_integer_dtype
>>> is_signed_integer_dtype(str)
False
>>> is_signed_integer_dtype(int)
True
>>> is_signed_integer_dtype(float)
False
>>> is_signed_integer_dtype(np.uint64)  # unsigned
False
>>> is_signed_integer_dtype('int8')
True
>>> is_signed_integer_dtype('Int8')
True
>>> is_signed_integer_dtype(pd.Int8Dtype)
True
>>> is_signed_integer_dtype(np.datetime64)
False
>>> is_signed_integer_dtype(np.timedelta64)
False
>>> is_signed_integer_dtype(np.array(['a', 'b']))
False
>>> is_signed_integer_dtype(pd.Series([1, 2]))
True
>>> is_signed_integer_dtype(np.array([], dtype=np.timedelta64))
False
>>> is_signed_integer_dtype(pd.Index([1, 2.]))  # float
False
>>> is_signed_integer_dtype(np.array([1, 2], dtype=np.uint32))  # unsigned
False 

pandas.api.types.is_string_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_string_dtype.html

pandas.api.types.is_string_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为字符串数据类型。

如果传入的是对象数据类型的数组,则元素必须被推断为字符串。

参数:

arr_or_dtype:数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为字符串数据类型。

示例

>>> from pandas.api.types import is_string_dtype
>>> is_string_dtype(str)
True
>>> is_string_dtype(object)
True
>>> is_string_dtype(int)
False
>>> is_string_dtype(np.array(['a', 'b']))
True
>>> is_string_dtype(pd.Series([1, 2]))
False
>>> is_string_dtype(pd.Series([1, 2], dtype=object))
False 

pandas.api.types.is_timedelta64_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_timedelta64_dtype.html

pandas.api.types.is_timedelta64_dtype(arr_or_dtype)

检查数组或数据类型是否为 timedelta64 数据类型。

参数:

arr_or_dtype数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为 timedelta64 数据类型。

示例

>>> from pandas.core.dtypes.common import is_timedelta64_dtype
>>> is_timedelta64_dtype(object)
False
>>> is_timedelta64_dtype(np.timedelta64)
True
>>> is_timedelta64_dtype([1, 2, 3])
False
>>> is_timedelta64_dtype(pd.Series([], dtype="timedelta64[ns]"))
True
>>> is_timedelta64_dtype('0 days')
False 

pandas.api.types.is_timedelta64_ns_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_timedelta64_ns_dtype.html

pandas.api.types.is_timedelta64_ns_dtype(arr_or_dtype)

检查提供的数组或数据类型是否为 timedelta64[ns]数据类型。

这是一个非常特定的数据类型,因此像 np.timedelta64 这样的通用类型如果传递给这个函数,将会返回 False。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回值:

布尔值

数组或数据类型是否为 timedelta64[ns]数据类型。

示例

>>> from pandas.core.dtypes.common import is_timedelta64_ns_dtype
>>> is_timedelta64_ns_dtype(np.dtype('m8[ns]'))
True
>>> is_timedelta64_ns_dtype(np.dtype('m8[ps]'))  # Wrong frequency
False
>>> is_timedelta64_ns_dtype(np.array([1, 2], dtype='m8[ns]'))
True
>>> is_timedelta64_ns_dtype(np.array([1, 2], dtype=np.timedelta64))
False 

pandas.api.types.is_unsigned_integer_dtype

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_unsigned_integer_dtype.html

pandas.api.types.is_unsigned_integer_dtype(arr_or_dtype)

检查所提供的数组或数据类型是否为无符号整数数据类型。

可空整数数据类型(例如 pandas.UInt64Dtype)也被此函数视为整数。

参数:

arr_or_dtype类似数组或数据类型

要检查的数组或数据类型。

返回:

布尔值

数组或数据类型是否为无符号整数数据类型。

示例

>>> from pandas.api.types import is_unsigned_integer_dtype
>>> is_unsigned_integer_dtype(str)
False
>>> is_unsigned_integer_dtype(int)  # signed
False
>>> is_unsigned_integer_dtype(float)
False
>>> is_unsigned_integer_dtype(np.uint64)
True
>>> is_unsigned_integer_dtype('uint8')
True
>>> is_unsigned_integer_dtype('UInt8')
True
>>> is_unsigned_integer_dtype(pd.UInt8Dtype)
True
>>> is_unsigned_integer_dtype(np.array(['a', 'b']))
False
>>> is_unsigned_integer_dtype(pd.Series([1, 2]))  # signed
False
>>> is_unsigned_integer_dtype(pd.Index([1, 2.]))  # float
False
>>> is_unsigned_integer_dtype(np.array([1, 2], dtype=np.uint32))
True 

pandas.api.types.is_sparse

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_sparse.html

pandas.api.types.is_sparse(arr)

检查类似数组是否为 1-D pandas 稀疏数组。

自 2.1.0 版本起已弃用:请使用 isinstance(dtype, pd.SparseDtype)代替。

检查一维类似数组是否为 pandas 稀疏数组。如果是 pandas 稀疏数组而不是其他类型的稀疏数组,则返回 True。

参数:

arr类似于数组

要检查的类似数组。

返回:

布尔值

类似数组是否为 pandas 稀疏数组。

示例

如果参数是 1-D pandas 稀疏数组,则返回 True。

>>> from pandas.api.types import is_sparse
>>> is_sparse(pd.arrays.SparseArray([0, 0, 1, 0]))
True
>>> is_sparse(pd.Series(pd.arrays.SparseArray([0, 0, 1, 0])))
True 

如果参数不是稀疏的,则返回 False。

>>> is_sparse(np.array([0, 0, 1, 0]))
False
>>> is_sparse(pd.Series([0, 1, 0, 0]))
False 

如果参数不是 pandas 稀疏数组,则返回 False。

>>> from scipy.sparse import bsr_matrix
>>> is_sparse(bsr_matrix([0, 1, 0, 0]))
False 

如果参数具有多于一个维度,则返回 False。

pandas.api.types.is_dict_like

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_dict_like.html

pandas.api.types.is_dict_like(obj)

检查对象是否类似于字典。

参数:

obj 要检查的对象

返回结果:

布尔值

obj 是否具有类似于字典的属性。

示例

>>> from pandas.api.types import is_dict_like
>>> is_dict_like({1: 2})
True
>>> is_dict_like([1, 2, 3])
False
>>> is_dict_like(dict)
False
>>> is_dict_like(dict())
True 

pandas.api.types.is_file_like

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_file_like.html

pandas.api.types.is_file_like(obj)

检查对象是否为类似文件的对象。

要被视为类似文件的对象,它们必须是迭代器,并且具有读取和/或写入方法作为属性之一。

注意:类似文件的对象必须是可迭代的,但可迭代的对象不一定是类似文件的。

参数:

obj要检查的对象

返回:

布尔值

obj 是否具有类似文件的属性。

示例

>>> import io
>>> from pandas.api.types import is_file_like
>>> buffer = io.StringIO("data")
>>> is_file_like(buffer)
True
>>> is_file_like([1, 2, 3])
False 

pandas.api.types.is_list_like

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_list_like.html

pandas.api.types.is_list_like(obj, allow_sets=True)

检查对象是否类似列表。

被视为类似列表的对象包括 Python 列表、元组、集合、NumPy 数组和 Pandas Series。

然而,字符串和日期时间对象不被视为类似列表。

参数:

obj对象

要检查的对象。

allow_sets布尔值,默认为 True

如果此参数为 False,则集合将不被视为类似列表。

返回:

布尔值

是否 obj 具有类似列表的属性。

示例

>>> import datetime
>>> from pandas.api.types import is_list_like
>>> is_list_like([1, 2, 3])
True
>>> is_list_like({1, 2, 3})
True
>>> is_list_like(datetime.datetime(2017, 1, 1))
False
>>> is_list_like("foo")
False
>>> is_list_like(1)
False
>>> is_list_like(np.array([2]))
True
>>> is_list_like(np.array(2))
False 

pandas.api.types.is_named_tuple

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_named_tuple.html

pandas.api.types.is_named_tuple(obj)

检查对象是否为命名元组。

参数:

obj要检查的对象

返回:

布尔值

obj 是否为命名元组。

示例

>>> from collections import namedtuple
>>> from pandas.api.types import is_named_tuple
>>> Point = namedtuple("Point", ["x", "y"])
>>> p = Point(1, 2)
>>>
>>> is_named_tuple(p)
True
>>> is_named_tuple((1, 2))
False 

pandas.api.types.is_iterator

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_iterator.html

pandas.api.types.is_iterator(obj)

检查对象是否为迭代器。

这适用于生成器,而不是类似列表的对象。

参数:

obj需要检查的对象

返回值:

is_iter布尔值

obj 是否为迭代器。

示例

>>> import datetime
>>> from pandas.api.types import is_iterator
>>> is_iterator((x for x in []))
True
>>> is_iterator([1, 2, 3])
False
>>> is_iterator(datetime.datetime(2017, 1, 1))
False
>>> is_iterator("foo")
False
>>> is_iterator(1)
False 

pandas.api.types.is_bool

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_bool.html

pandas.api.types.is_bool(obj)

如果给定对象是布尔值,则返回 True。

返回值:

布尔值

示例

>>> pd.api.types.is_bool(True)
True 
>>> pd.api.types.is_bool(1)
False 

pandas.api.types.is_complex

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_complex.html

pandas.api.types.is_complex(obj)

如果给定对象是复数,则返回 True。

返回:

布尔值

示例

>>> pd.api.types.is_complex(1 + 1j)
True 
>>> pd.api.types.is_complex(1)
False 

pandas.api.types.is_float

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_float.html

pandas.api.types.is_float(obj)

如果给定对象是浮点数,则返回 True。

返回:

布尔

示例

>>> pd.api.types.is_float(1.0)
True 
>>> pd.api.types.is_float(1)
False 

pandas.api.types.is_hashable

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_hashable.html

pandas.api.types.is_hashable(obj)

如果hash(obj)成功,则返回 True,否则返回 False。

一些类型可能通过collections.abc.Hashable的测试,但在实际使用hash()时会失败。

通过尝试调用hash()并查看是否引发 TypeError 来区分这些类型和其他类型。

返回:

布尔值

例子

>>> import collections
>>> from pandas.api.types import is_hashable
>>> a = ([],)
>>> isinstance(a, collections.abc.Hashable)
True
>>> is_hashable(a)
False 

pandas.api.types.is_integer

pandas.pydata.org/docs/reference/api/pandas.api.types.is_integer.html

pandas.api.types.is_integer(obj)

如果给定对象是整数,则返回 True。

返回:

布尔值

示例

>>> pd.api.types.is_integer(1)
True 
>>> pd.api.types.is_integer(1.0)
False 

pandas.api.types.is_interval

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_interval.html

pandas.api.types.is_interval(obj)

pandas.api.types.is_number

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_number.html

pandas.api.types.is_number(obj)

检查对象是否为数字。

当对象为数字时返回 True,否则返回 False。

参数:

obj 任意类型

要检查是否为数字的对象。

返回:

布尔值

obj 是否为数字。

另请参阅

api.types.is_integer

检查一组数字的子组。

示例

>>> from pandas.api.types import is_number
>>> is_number(1)
True
>>> is_number(7.15)
True 

布尔值有效,因为它们是 int 的子类。

>>> is_number(False)
True 
>>> is_number("foo")
False
>>> is_number("5")
False 

pandas.api.types.is_re

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_re.html

pandas.api.types.is_re(obj)

检查对象是否为正则表达式模式实例。

参数:

obj 要检查的对象

返回:

布尔值

obj 是否为正则表达式模式。

示例

>>> from pandas.api.types import is_re
>>> import re
>>> is_re(re.compile(".*"))
True
>>> is_re("foo")
False 

pandas.api.types.is_re_compilable

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_re_compilable.html

pandas.api.types.is_re_compilable(obj)

检查对象是否可以编译成正则表达式模式实例。

参数:

obj需要检查的对象

返回值:

布尔值

obj 是否可以编译为正则表达式模式。

示例

>>> from pandas.api.types import is_re_compilable
>>> is_re_compilable(".*")
True
>>> is_re_compilable(1)
False 

pandas.api.types.is_scalar

原文:pandas.pydata.org/docs/reference/api/pandas.api.types.is_scalar.html

pandas.api.types.is_scalar(val)

如果给定对象是标量,则返回 True。

参数:

val对象

这包括:

  • numpy 数组标量(例如 np.int64)

  • Python 内置数值类型

  • Python 内置的字节数组和字符串

  • None

  • datetime.datetime

  • datetime.timedelta

  • 期间

  • decimal.Decimal

  • 区间

  • DateOffset

  • 分数

  • 数字。

返回:

布尔值

如果给定对象是标量,则返回 True。

示例

>>> import datetime
>>> dt = datetime.datetime(2018, 10, 3)
>>> pd.api.types.is_scalar(dt)
True 
>>> pd.api.types.is_scalar([2, 3])
False 
>>> pd.api.types.is_scalar({0: 1, 2: 3})
False 
>>> pd.api.types.is_scalar((0, 2))
False 

pandas 支持 PEP 3141 数字:

>>> from fractions import Fraction
>>> pd.api.types.is_scalar(Fraction(3, 5))
True 

索引对象

原文:pandas.pydata.org/docs/reference/indexing.html

索引

这些方法或其变体中的许多方法可用于包含索引的对象(Series/DataFrame),在直接调用这些方法之前,应该首选使用这些对象。

Index([data, dtype, copy, name, tupleize_cols]) 用于索引和对齐的不可变序列。

属性

Index.values 返回表示索引中数据的数组。
Index.is_monotonic_increasing 如果值相等或递增,则返回布尔值。
Index.is_monotonic_decreasing 如果值相等或递减,则返回布尔值。
Index.is_unique 返回索引是否具有唯一值。
Index.has_duplicates 检查索引是否具有重复值。
Index.hasnans 如果存在任何 NaN,则返回 True。
Index.dtype 返回底层数据的 dtype 对象。
Index.inferred_type 返回从值推断的类型的字符串。
Index.shape 返回底层数据的形状的元组。
Index.name 返回索引或多重索引的名称。
Index.names
Index.nbytes 返回底层数据中的字节数。
Index.ndim 底层数据的维数,根据定义为 1。
Index.size 返回底层数据中的元素数。
Index.empty
Index.T 返回转置,根据定义为自身。
Index.memory_usage([deep]) 值的内存使用量。

修改和计算

Index.all(*args, **kwargs) 返回所有元素是否为真值。
Index.any(*args, **kwargs) 返回是否存在任何元素为真值。
Index.argmin([axis, skipna]) 返回 Series 中最小值的整数位置。
Index.argmax([axis, skipna]) 返回 Series 中最大值的整数位置。
Index.copy([name, deep]) 复制此对象。
Index.delete(loc) 使用传入的位置删除索引中的项目。
Index.drop(labels[, errors]) 使用传入的标签列表创建新的索引,删除指定标签。
Index.drop_duplicates(*[, keep]) 返回删除重复值后的索引。
Index.duplicated([keep]) 指示重复的索引值。
Index.equals(other) 判断两个索引对象是否相等。
Index.factorize([sort, use_na_sentinel]) 将对象编码为枚举类型或分类变��。
Index.identical(other) 类似于 equals,但还检查对象属性和类型是否相等。
Index.insert(loc, item) 在指定位置插入新项目,创建新的索引。
Index.is_(other) 更灵活、更快速的检查,类似于 is,但可以通过视图操作。
Index.is_boolean() (已弃用) 检查索引是否仅包含布尔值。
Index.is_categorical() (已弃用) 检查索引是否包含分类数据。
Index.is_floating() (已弃用) 检查索引是否为浮点类型。
Index.is_integer() (已弃用) 检查索引是否仅包含整数。
Index.is_interval() (已弃用) 检查索引是否包含区间对象。
Index.is_numeric() (已弃用) 检查索引是否仅包含数值数据。
Index.is_object() (已弃用) 检查索引是否为对象数据类型。
Index.min([axis, skipna]) 返回索引的最小值。
Index.max([axis, skipna]) 返回索引的最大值。
Index.reindex(target[, method, level, ...]) 使用目标值创建索引。
Index.rename(name, *[, inplace]) 更改索引或多级索引的名称。
Index.repeat(repeats[, axis]) 重复索引的元素。
Index.where(cond[, other]) 替换条件为假的值。
Index.take(indices[, axis, allow_fill, ...]) 返回由索引选定的值的新索引。
Index.putmask(mask, value) 返回使用掩码设置的新索引。
Index.unique([level]) 返回索引中的唯一值。
Index.nunique([dropna]) 返回对象中唯一元素的数量。
Index.value_counts([normalize, sort, ...]) 返回包含唯一值计数的 Series。

与 MultiIndex 兼容性

Index.set_names(names, *[, level, inplace]) 设置索引或多级索引的名称。
Index.droplevel([level]) 返回删除请求级别的索引。

缺失值

Index.fillna([value, downcast]) 用指定值填充 NA/NaN 值。
Index.dropna([how]) 返回没有 NA/NaN 值的索引。
Index.isna() 检测缺失值。
Index.notna() 检测存在的(非缺失)值。

转换

Index.astype(dtype[, copy]) 创建一个将值转换为指定数据类型的索引。
Index.item() 将底层数据的第一个元素作为 Python 标量返回。
Index.map(mapper[, na_action]) 使用输入映射或函数映射值。
Index.ravel([order]) 返回自身的视图。
Index.to_list() 返回值的列表。
Index.to_series([index, name]) 创建一个既包含索引又包含值等于索引键的 Series。
Index.to_frame([index, name]) 创建一个包含索引的列的 DataFrame。
Index.view([cls])

排序

Index.argsort(*args, **kwargs) 返回将索引排序的整数索引。
Index.searchsorted(value[, side, sorter]) 找到应插入元素以保持顺序的索引位置。
Index.sort_values(*[, return_indexer, ...]) 返回索引的排序副本。

时间特定操作

Index.shift([periods, freq]) 将索引按所需的时间频率增量进行移动。

合并/连接/集合操作

Index.append(other) 将一组索引选项连接在一起。
Index.join(other, *[, how, level, ...]) 计算 join_index 和 indexers 以使数据结构符合新索引。
Index.intersection(other[, sort]) 形成两个索引对象的交集。
Index.union(other[, sort]) 形成两个索引对象的并集。
Index.difference(other[, sort]) 返回一个新的索引,其中包含不在其他索引中的元素。
Index.symmetric_difference(other[, ...]) 计算两个索引对象的对称差。

选择

Index.asof(label) 返回索引中的标签,如果不存在,则返回前一个标签。
Index.asof_locs(where, mask) 返回索引中标签的位置(索引)。
Index.get_indexer(target[, method, limit, ...]) 给定当前索引,计算新索引的索引器和掩码。
Index.get_indexer_for(target) 即使非唯一,也保证返回索引器。
Index.get_indexer_non_unique(target) 给定当前索引,计算新索引的索引器和掩码。
Index.get_level_values(level) 返回请求级别的值索引。
Index.get_loc(key) 获取请求标签的整数位置、切片或布尔掩码。
Index.get_slice_bound(label, side) 计算与给定标签对应的切片边界。
Index.isin(values[, level]) 返回一个布尔数组,其中索引值在给定值中。
Index.slice_indexer([start, end, step]) 计算输入标签和步长的切片索引器。
Index.slice_locs([start, end, step]) 计算输入标签的切片位置。

数字索引

RangeIndex([start, stop, step, dtype, copy, ...]) 实现单调整数范围的不可变索引。
RangeIndex.start 起始参数的值(如果未提供则为0)。
RangeIndex.stop 停止参数的值。
RangeIndex.step 步长参数的值(如果未提供则为1)。

| RangeIndex.from_range(data[, name, dtype]) | 从range对象创建pandas.RangeIndex。 | ## CategoricalIndex

CategoricalIndex([data, categories, ...]) 基于底层Categorical的索引。

Categorical components

CategoricalIndex.codes 此类别索引的类别编码。
CategoricalIndex.categories 此类别的类别。
CategoricalIndex.ordered 类别是否具有有序关系。
CategoricalIndex.rename_categories(*args, ...) 重命名类别。
CategoricalIndex.reorder_categories(*args, ...) 按照新类别中指定的顺序重新排序类别。
CategoricalIndex.add_categories(*args, **kwargs) 添加新的类别。
CategoricalIndex.remove_categories(*args, ...) 删除指定的类别。
CategoricalIndex.remove_unused_categories(...) 删除未使用的类别。
CategoricalIndex.set_categories(*args, **kwargs) 将类别设置为指定的新类别。
CategoricalIndex.as_ordered(*args, **kwargs) 将分类设置为有序。
CategoricalIndex.as_unordered(*args, **kwargs) 将分类设置为无序。

修改和计算

CategoricalIndex.map(mapper[, na_action]) 使用输入的映射或函数映射值。

| CategoricalIndex.equals(other) | 确定两个 CategoricalIndex 对象是否包含相同的元素。 | ## IntervalIndex

IntervalIndex(data[, closed, dtype, copy, ...]) 不可变索引,包含在同一侧上关闭的区间。

区间索引组件

IntervalIndex.from_arrays(left, right[, ...]) 从定义左右边界的两个数组构造。
IntervalIndex.from_tuples(data[, closed, ...]) 从类似元组的数组构造一个区间索引。
IntervalIndex.from_breaks(breaks[, closed, ...]) 从数组拆分构造一个区间索引。
IntervalIndex.left
IntervalIndex.right
IntervalIndex.mid
IntervalIndex.closed 描述区间的包含侧的字符串。
IntervalIndex.length
IntervalIndex.values 返回表示索引中数据的数组。
IntervalIndex.is_empty 表示区间是否为空,即不包含任何点。
IntervalIndex.is_non_overlapping_monotonic 返回一个布尔值,指示 IntervalArray 是否不重叠且单调。
IntervalIndex.is_overlapping 如果 IntervalIndex 具有重叠的区间,则返回 True,否则返回 False。
IntervalIndex.get_loc(key) 获取请求标签的整数位置、切片或布尔掩码。
IntervalIndex.get_indexer(target[, method, ...]) 给定当前索引,计算新索引的索引器和掩码。
IntervalIndex.set_closed(*args, **kwargs) 返回一个在指定侧关闭的相同 IntervalArray。
IntervalIndex.contains(*args, **kwargs) 逐个元素检查区间是否包含该值。
IntervalIndex.overlaps(*args, **kwargs) 逐个元素检查一个区间是否与 IntervalArray 中的值重叠。

| IntervalIndex.to_tuples(*args, **kwargs) | 返回形式为 (left, right) 的元组的 ndarray(如果 self 是 IntervalArray)或 Index(如果 self 是 IntervalIndex)。 | ## MultiIndex

MultiIndex([levels, codes, sortorder, ...]) 用于 pandas 对象的多级索引对象。

MultiIndex 构造函数

MultiIndex.from_arrays(arrays[, sortorder, ...]) 将数组转换为 MultiIndex。
MultiIndex.from_tuples(tuples[, sortorder, ...]) 将元组列表转换为 MultiIndex。
MultiIndex.from_product(iterables[, ...]) 从多个可迭代对象的笛卡尔积创建 MultiIndex。
MultiIndex.from_frame(df[, sortorder, names]) 从 DataFrame 创建 MultiIndex。

MultiIndex 属性

MultiIndex.names MultiIndex 中级别的名称。
MultiIndex.levels MultiIndex 的级别。
MultiIndex.codes
MultiIndex.nlevels 此 MultiIndex 中级别的整数数量。
MultiIndex.levshape 每个级别的长度的元组。
MultiIndex.dtypes 返回基础 MultiIndex 的 dtypes 作为 Series。

MultiIndex 组件

MultiIndex.set_levels(levels, *[, level, ...]) 在 MultiIndex 上设置新的级别。
MultiIndex.set_codes(codes, *[, level, ...]) 在 MultiIndex 上设置新的代码。
MultiIndex.to_flat_index() 将 MultiIndex 转换为包含级别值的元组索引。
MultiIndex.to_frame([index, name, ...]) 创建一个 DataFrame,其中 MultiIndex 的级别作为列。
MultiIndex.sortlevel([level, ascending, ...]) 在请求的级别上对 MultiIndex 进行排序。
MultiIndex.droplevel([level]) 返回删除请求级别的索引。
MultiIndex.swaplevel([i, j]) 交换级别 i 和级别 j。
MultiIndex.reorder_levels(order) 使用输入顺序重新排列级别。
MultiIndex.remove_unused_levels() 从当前 MultiIndex 创建一个新的 MultiIndex,删除未使用的级别。
MultiIndex.drop(codes[, level, errors]) 使用传递的代码列表创建一个新的 pandas.MultiIndex
MultiIndex.copy 复制此对象。
MultiIndex.append(other) 将一组索引选项追加在一起。
MultiIndex.truncate([before, after]) 在两个标签/元组之间切片索引,返回新的 MultiIndex。

多重索引选择

MultiIndex.get_loc(key) 获取标签或标签元组的位置。
MultiIndex.get_locs(seq) 获取一系列标签的位置。
MultiIndex.get_loc_level(key[, level, ...]) 获取请求的标签/级别的位置和切片索引。
MultiIndex.get_indexer(target[, method, ...]) 给定��前索引,计算新索引的索引器和掩码。
MultiIndex.get_level_values(level) 返回请求级别的标签值向量。

| IndexSlice | 创建一个对象,更容易执行多重索引切片。 | ## DatetimeIndex

DatetimeIndex([data, freq, tz, normalize, ...]) 不可变的 datetime64 数据类似的 ndarray。

时间/日期组件

DatetimeIndex.year 日期时间的年份。
DatetimeIndex.month 月份,一月为 1,十二月为 12。
DatetimeIndex.day 日期时间的日期。
DatetimeIndex.hour 日期时间的小时数。
DatetimeIndex.minute 日期时间的分钟数。
DatetimeIndex.second 日期时间的秒数。
DatetimeIndex.microsecond 日期时间的微秒数。
DatetimeIndex.nanosecond 日期的纳秒。
DatetimeIndex.date 返回 python datetime.date 对象的 numpy 数组。
DatetimeIndex.time 返回带有时区的 python datetime.time 对象的 numpy 数组。
DatetimeIndex.timetz 返回带有时区的 python datetime.time 对象的 numpy 数组。
DatetimeIndex.dayofyear 年份中的第几天。
DatetimeIndex.day_of_year 年份中的第几天。
DatetimeIndex.dayofweek 一周的第几天,星期一为 0,星期日为 6。
DatetimeIndex.day_of_week 一周的第几天,星期一为 0,星期日为 6。
DatetimeIndex.weekday 一周的第几天,星期一为 0,星期日为 6。
DatetimeIndex.quarter 日期的季度。
DatetimeIndex.tz 返回时区。
DatetimeIndex.freq
DatetimeIndex.freqstr 如果已设置,则返回频率对象的字符串,否则返回 None。
DatetimeIndex.is_month_start 表示日期是否为月初。
DatetimeIndex.is_month_end 表示日期是否为月末。
DatetimeIndex.is_quarter_start 指示日期是否为一个季度的第一天。
DatetimeIndex.is_quarter_end 指示日期是否为一个季度的最后一天。
DatetimeIndex.is_year_start 表示日期是否为一年的第一天。
DatetimeIndex.is_year_end 表示日期是否为一年的最后一天。
DatetimeIndex.is_leap_year 布尔指示器,指示日期是否属于闰年。
DatetimeIndex.inferred_freq 尝试返回由 infer_freq 生成的表示频率的字符串。

选择

DatetimeIndex.indexer_at_time(time[, asof]) 返回特定时间一天中值的索引位置。
DatetimeIndex.indexer_between_time(...[, ...]) 返回在一天特定时间之间的值的索引位置。

特定时间操作

DatetimeIndex.normalize(*args, **kwargs) 将时间转换为午夜。
DatetimeIndex.strftime(date_format) 使用指定的日期格式转换为索引。
DatetimeIndex.snap([freq]) 将时间戳捕捉到最近发生的频率。
DatetimeIndex.tz_convert(tz) 将一个时区感知的日期时间数组/索引从一个时区转换为另一个时区。
DatetimeIndex.tz_localize(tz[, ambiguous, ...]) 将 tz-naive 日期时间数组/索引本地化为 tz-aware 日期时间数组/索引。
DatetimeIndex.round(*args, **kwargs) 对数据执行舍入操作,以指定的频率。
DatetimeIndex.floor(*args, **kwargs) 对数据执行向下取整操作,以指定的频率。
DatetimeIndex.ceil(*args, **kwargs) 对数据执行向上取整操作,以指定的频率。
DatetimeIndex.month_name(*args, **kwargs) 返回指定语言环境的月份名称。
DatetimeIndex.day_name(*args, **kwargs) 返回指定语言环境的星期几名称。

转换

DatetimeIndex.as_unit(*args, **kwargs) 转换为具有给定单位分辨率的 dtype。
DatetimeIndex.to_period(*args, **kwargs) 在特定频率下转换为 PeriodArray/PeriodIndex。
DatetimeIndex.to_pydatetime(*args, **kwargs) 返回一个包含 datetime.datetime 对象的 ndarray。
DatetimeIndex.to_series([index, name]) 创建一个 Series,其索引和值都等于索引键。
DatetimeIndex.to_frame([index, name]) 创建一个包含索引的列的 DataFrame。

方法

DatetimeIndex.mean(*[, skipna, axis]) 返回数组的平均值。
DatetimeIndex.std(*args, **kwargs) 返回请求轴上的样本标准差。

TimedeltaIndex

TimedeltaIndex([data, unit, freq, closed, ...]) 不可变的 timedelta64 数据索引。

组件

TimedeltaIndex.days 每个元素的天数。
TimedeltaIndex.seconds 每个元素的秒数(>= 0 且小于 1 天)。
TimedeltaIndex.microseconds 每个元素的微秒数(>= 0 且小于 1 秒)。
TimedeltaIndex.nanoseconds 每个元素的纳秒数(>= 0 且小于 1 微秒)。
TimedeltaIndex.components 返回 Timedeltas 的各个分辨率组件的 DataFrame。
TimedeltaIndex.inferred_freq 尝试返回由 infer_freq 生成的表示频率的字符串。

Conversion

TimedeltaIndex.as_unit(unit) 转换为具有给定单位分辨率的 dtype。
TimedeltaIndex.to_pytimedelta(*args, **kwargs) 返回一个 datetime.timedelta 对象的 ndarray。
TimedeltaIndex.to_series([index, name]) 创建一个索引和值都等于索引键的 Series。
TimedeltaIndex.round(*args, **kwargs) 对数据执行四舍五入操作,以指定的频率为准。
TimedeltaIndex.floor(*args, **kwargs) 对数据执行向下取整操作,以指定的频率为准。
TimedeltaIndex.ceil(*args, **kwargs) 对数据执行向上取整操作,以指定的频率为准。
TimedeltaIndex.to_frame([index, name]) 创建一个包含索引的列的 DataFrame。

Methods

TimedeltaIndex.mean(*[, skipna, axis]) 返回数组的平均值。

PeriodIndex

PeriodIndex([data, ordinal, freq, dtype, ...]) 不可变的 ndarray,包含指示时间中常规周期的序数值。

Properties

PeriodIndex.day 该周期的天数。
PeriodIndex.dayofweek 一周中的日期,星期一为 0,星期日为 6。
PeriodIndex.day_of_week 一周中的日期,星期一为 0,星期日为 6。
PeriodIndex.dayofyear 一年中的序数日期。
PeriodIndex.day_of_year 一年中的序数日期。
PeriodIndex.days_in_month 一个月的天数。
PeriodIndex.daysinmonth 一个月的天数。
PeriodIndex.end_time 获取期间结束的时间戳。
PeriodIndex.freq
PeriodIndex.freqstr 返回频率对象的字符串,如果设置了,则返回字符串,否则返回 None。
PeriodIndex.hour 期间的小时数。
PeriodIndex.is_leap_year 逻辑指示日期是否属于闰年。
PeriodIndex.minute 期间的分钟数。
PeriodIndex.month 月份,一月为 1,十二月为 12。
PeriodIndex.quarter 日期的季度。
PeriodIndex.qyear
PeriodIndex.second 期间的秒数。
PeriodIndex.start_time 获取期间开始的时间戳。
PeriodIndex.week 一年中的周序数。
PeriodIndex.weekday 一周中的日期,星期一=0,星期日=6。
PeriodIndex.weekofyear 年份的周序数。
PeriodIndex.year 该时期的年份。

方法

PeriodIndex.asfreq([freq, how]) 将 PeriodArray 转换为指定频率 freq。
PeriodIndex.strftime(*args, **kwargs) 使用指定的日期格式转换为索引。
PeriodIndex.to_timestamp([freq, how]) 转换为 DatetimeArray/Index。
PeriodIndex.from_fields(*[, year, quarter, ...])
PeriodIndex.from_ordinals(ordinals, *, freq)

索引

这些方法或其变体多数可用于包含索引的对象(Series/DataFrame),在直接调用这些方法之前,应该首选使用这些对象。

Index([data, dtype, copy, name, tupleize_cols]) 用于索引和对齐的不可变序列。

属性

Index.values 返回表示索引中数据的数组。
Index.is_monotonic_increasing 如果值相等或递增,则返回布尔值。
Index.is_monotonic_decreasing 如果值相等或递减,则返回布尔值。
Index.is_unique 返回索引是否具有唯一值。
Index.has_duplicates 检查索引是否具有重复值。
Index.hasnans 如果存在任何 NaN,则返回 True。
Index.dtype 返回基础数据的 dtype 对象。
Index.inferred_type 返回从值推断的类型的字符串。
Index.shape 返回底层数据的形状的元组。
Index.name 返回 Index 或 MultiIndex 的名称。
Index.names
Index.nbytes 返回底层数据的字节数。
Index.ndim 底层数据的维数,按定义为 1。
Index.size 返回底层数据中的元素数量。
Index.empty
Index.T 返回转置,根据定义为自身。
Index.memory_usage([deep]) 值的内存使用情况。

修改和计算

Index.all(*args, **kwargs) 返回是否所有元素都为 Truthy。
Index.any(*args, **kwargs) 返回是否存在任何 Truthy 元素。
Index.argmin([axis, skipna]) 返回 Series 中最小值的整数位置。
Index.argmax([axis, skipna]) 返回 Series 中最大值的整数位置。
Index.copy([name, deep]) 复制此对象。
Index.delete(loc) 使用传递的位置删除新的 Index。
Index.drop(labels[, errors]) 使用传递的标签列表创建新的 Index。
Index.drop_duplicates(*[, keep]) 返回删除重复值的 Index。
Index.duplicated([keep]) 指示重复的索引值。
Index.equals(other) 确定两个 Index 对象是否相等。
Index.factorize([sort, use_na_sentinel]) 将对象编码为枚举类型或分类变量。
Index.identical(other) 类似于 equals,但检查对象属性和类型也相等。
Index.insert(loc, item) 在指定位置插入新项,生成新索引。
Index.is_(other) 更灵活、更快速的检查,类似于is但可以通过视图操作。
Index.is_boolean() (已弃用) 检查索引是否仅包含布尔值。
Index.is_categorical() (已弃用) 检查索引是否持有分类数据。
Index.is_floating() (已弃用) 检查索引是否为浮点类型。
Index.is_integer() (已弃用) 检查索引是否仅由整数组成。
Index.is_interval() (已弃用) 检查索引是否持有 Interval 对象。
Index.is_numeric() (已弃用) 检查索引是否仅包含数值数据。
Index.is_object() (已弃用) 检查索引是否为对象 dtype。
Index.min([axis, skipna]) 返回索引的最小值。
Index.max([axis, skipna]) 返回索引的最大值。
Index.reindex(target[, method, level, ...]) 使用目标的值创建索引。
Index.rename(name, *[, inplace]) 更改索引或多级索引的名称。
Index.repeat(repeats[, axis]) 重复索引的元素。
Index.where(cond[, other]) 替换条件为 False 的值。
Index.take(indices[, axis, allow_fill, ...]) 返回由索引选定的值组成的新索引。
Index.putmask 返回使用掩码设置的新值索引。
Index.unique 返回索引中的唯一值。
Index.nunique 返回对象中唯一元素的数量。
Index.value_counts 返回包含唯一值计数的 Series。

与 MultiIndex 兼容性

Index.set_names 设置索引或 MultiIndex 名称。
Index.droplevel 返回删除了请求级别的索引。

缺失值

Index.fillna 用指定值填充 NA/NaN 值。
Index.dropna 返回没有 NA/NaN 值的索引。
Index.isna 检测缺失值。
Index.notna 检测存在(非缺失)值。

转换

Index.astype 创建一个将值强制转换为 dtypes 的索引。
Index.item 以 Python 标量形式返回底层数据的第一个元素。
Index.map 使用输入映射或函数映射值。
Index.ravel 返回自身的视图。
Index.to_list 返回值的列表。
Index.to_series 创建一个索引和值都等于索引键的 Series。
Index.to_frame 创建一个包含索引的列的 DataFrame。
Index.view

排序

Index.argsort 返回对索引进行排序的整数索引。
Index.searchsorted(value[, side, sorter]) 查找元素应插入以保持顺序的索引。
Index.sort_values(*[, return_indexer, ...]) 返回索引的排序副本。

时间特定操作

Index.shift([periods, freq]) 将索引按所需的时间频率增量移动。

组合/连接/集合操作

Index.append(other) 将一系列索引选项追加在一起。
Index.join(other, *[, how, level, ...]) 计算连接数据结构到新索引的 join_index 和索引器。
Index.intersection(other[, sort]) 形成两个索引对象的交集。
Index.union(other[, sort]) 形成两个索引对象的并集。
Index.difference(other[, sort]) 返回一个新的索引,其中包含不在其他索引中的元素。
Index.symmetric_difference(other[, ...]) 计算两个索引对象的对称差。

选择

Index.asof(label) 返回索引中的标签,如果不存在,则返回前一个。
Index.asof_locs(where, mask) 返回索引中标签的位置(索引)。
Index.get_indexer(target[, method, limit, ...]) 计算给定当前索引的新索引的索引器和掩码。
Index.get_indexer_for(target) 即使是非唯一的,也保证返回一个索引器。
Index.get_indexer_non_unique(target) 计算给定当前索引的新索引的索引器和掩码。
Index.get_level_values(level) 返回请求级别的值索引。
Index.get_loc(key) 获取请求标签的整数位置、切片或布尔掩码。
Index.get_slice_bound(label, side) 计算与给定标签对应的切片边界。
Index.isin(values[, level]) 返回一个布尔数组,其中索引值在给定的 values 中。
Index.slice_indexer([start, end, step]) 计算输入标签和步长的切片索引器。
Index.slice_locs([start, end, step]) 计算输入标签的切片位置。

属性

Index.values 返回表示索引中数据的数组。
Index.is_monotonic_increasing 如果值相等或递增,则返回布尔值。
Index.is_monotonic_decreasing 如果值相等或递减,则返回布尔值。
Index.is_unique 返回索引是否具有唯一值。
Index.has_duplicates 检查索引是否具有重复值。
Index.hasnans 如果存在 NaN 值,则返回 True。
Index.dtype 返回底层数据的 dtype 对象。
Index.inferred_type 返回从值中推断出的类型的字符串。
Index.shape 返回底层数据的形状的元组。
Index.name 返回索引或多重索引的名称。
Index.names
Index.nbytes 返回底层数据中的字节数。
Index.ndim 底层数据的维数,根据定义为 1。
Index.size 返回基础数据中的元素数。
Index.empty
Index.T 返回转置,这在定义上是自身。
Index.memory_usage([deep]) 值的内存使用情况。

修改和计算

Index.all(*args, **kwargs) 返回所有元素是否为真值。
Index.any(*args, **kwargs) 返回是否存在任何真值元素。
Index.argmin([axis, skipna]) 返回系列中最小值的整数位置。
Index.argmax([axis, skipna]) 返回系列中最大值的整数位置。
Index.copy([name, deep]) 复制此对象。
Index.delete(loc) 生成删除传递位置的新索引。
Index.drop(labels[, errors]) 生成删除传递标签列表的新索引。
Index.drop_duplicates(*[, keep]) 返回删除重复值的索引。
Index.duplicated([keep]) 指示重复的索引值。
Index.equals(other) 确定两个索引对象是否相等。
Index.factorize([sort, use_na_sentinel]) 将对象编码为枚举类型或分类变量。
Index.identical(other) 类似于 equals,但检查对象属性和类型是否也相等。
Index.insert(loc, item) 在位置插入新项目,生成新索引。
Index.is_(other) 更灵活、更快速的检查,类似于is,但适用于视图。
Index.is_boolean() (已弃用)检查索引是否仅由布尔值组成。
Index.is_categorical() (已弃用)检查索引是否包含分类数据。
Index.is_floating() (已弃用)检查索引是否为浮点类型。
Index.is_integer() (已弃用)检查索引是否仅由整数组成。
Index.is_interval() (已弃用)检查索引是否包含区间对象。
Index.is_numeric() (已弃用)检查索引是否仅包含数值数据。
Index.is_object() (已弃用)检查索引是否为对象数据类型。
Index.min([axis, skipna]) 返回索引的最小值。
Index.max([axis, skipna]) 返回索引的最大值。
Index.reindex(target[, method, level, ...]) 使用目标的值创建索引。
Index.rename(name, *[, inplace]) 更改索引或多级索引的名称。
Index.repeat(repeats[, axis]) 重复索引的元素。
Index.where(cond[, other]) 替换条件为假的值。
Index.take(indices[, axis, allow_fill, ...]) 返回由索引选择的值的新索引。
Index.putmask(mask, value) 返回使用掩码设置的新索引值。
Index.unique([level]) 返回索引中的唯一值。
Index.nunique([dropna]) 返回对象中唯一元素的数量。
Index.value_counts([normalize, sort, ...]) 返回包含唯一值计数的系列。

与多级索引兼容性

Index.set_names(names, *[, level, inplace]) 设置索引或多级索引的名称。
Index.droplevel([level]) 返回已删除请求级别的索引。

缺失数值

Index.fillna([value, downcast]) 用指定值填充 NA/NaN 值。
Index.dropna([how]) 返回不包含 NA/NaN 值的索引。
Index.isna() 检测缺失值。
Index.notna() 检测存在(非缺失)数值。

转换

Index.astype(dtype[, copy]) 创建一个值被转换为数据类型的索引。
Index.item() 作为 Python 标量返回底层数据的第一个元素。
Index.map(mapper[, na_action]) 使用输入映射或函数映射值。
Index.ravel([order]) 返回对自身的视图。
Index.to_list() 返回值的列表。
Index.to_series([index, name]) 创建一个序列,其索引和值都等于索引键。
Index.to_frame([index, name]) 创建一个包含索引的列的数据框。
Index.view([cls])

排序

Index.argsort(*args, **kwargs) 返回将索引排序的整数索引。
Index.searchsorted(value[, side, sorter]) 找到应插入以保持顺序的元素的索引。
Index.sort_values(*[, return_indexer, ...]) 返回索引的排序副本。

特定于时间的操作

Index.shift([periods, freq]) 按所需的时间频率增量移动索引。

合并 / 连接 / 集合操作

Index.append(other) 将一系列索引选项附加在一起。
Index.join(other, *[, how, level, ...]) 计算 join_index 和 indexers 以使数据结构符合新索引。
Index.intersection(other[, sort]) 形成两个索引对象的交集。
Index.union(other[, sort]) 形成两个索引对象的并集。
Index.difference(other[, sort]) 返回一个新的索引,其中包含不在其他索引中的元素。
Index.symmetric_difference(other[, ...]) 计算两个索引对象的对称差异。

选择

Index.asof(label) 返回索引中的标签,如果不存在,则返回前一个标签。
Index.asof_locs(where, mask) 返回索引中标签的位置(索引)。
Index.get_indexer(target[, method, limit, ...]) 给定当前索引,计算新索引的索引器和掩码。
Index.get_indexer_for(target) 即使是非唯一的情况,也保证返回一个索引器。
Index.get_indexer_non_unique(target) 给定当前索引,计算新索引的索引器和掩码。
Index.get_level_values(level) 返回请求级别的值的索引。
Index.get_loc(key) 获取请求标签的整数位置、切片或布尔掩码。
Index.get_slice_bound(label, side) 计算与给定标签对应的切片边界。
Index.isin(values[, level]) 返回索引值在值中的布尔数组。
Index.slice_indexer([start, end, step]) 计算输入标签和步长的切片索引器。
Index.slice_locs([start, end, step]) 计算输入标签的切片位置。

数值索引

RangeIndex([start, stop, step, dtype, copy, ...]) 实现单调整数范围的不可变索引。
RangeIndex.start 起始参数的值(如果未提供则为0)。
RangeIndex.stop 停止参数的值。
RangeIndex.step 步长参数的值(如果未提供则为1)。
RangeIndex.from_range(data[, name, dtype]) range对象创建pandas.RangeIndex

CategoricalIndex

CategoricalIndex([data, categories, ...]) 基于底层Categorical的索引。

分类组件

CategoricalIndex.codes 此分类索引的类别编码。
CategoricalIndex.categories 此分类的类别。
CategoricalIndex.ordered 类别是否具有有序关系。
CategoricalIndex.rename_categories(*args, ...) 重命名类别。
CategoricalIndex.reorder_categories(*args, ...) 根据新类别指定的顺序重新排序类别。
CategoricalIndex.add_categories(*args, **kwargs) 添加新的类别。
CategoricalIndex.remove_categories(*args, ...) 移除指定的类别。
CategoricalIndex.remove_unused_categories(...) 移除未使用的类别。
CategoricalIndex.set_categories(*args, **kwargs) 将类别设置为指定的新类别。
CategoricalIndex.as_ordered(*args, **kwargs) 将分类设为有序。
CategoricalIndex.as_unordered(*args, **kwargs) 将分类设为无序。

修改和计算

CategoricalIndex.map(mapper[, na_action]) 使用输入映射或函数映射值。
CategoricalIndex.equals(other) 确定两个 CategoricalIndex 对象是否包含相同的元素。

分类组件

CategoricalIndex.codes 此分类索引的类别代码。
CategoricalIndex.categories 此分类的类别。
CategoricalIndex.ordered 类别是否具有有序关系。
CategoricalIndex.rename_categories(*args, ...) 重命名类别。
CategoricalIndex.reorder_categories(*args, ...) 按照 new_categories 中指定的顺序重新排序类别。
CategoricalIndex.add_categories(*args, **kwargs) 添加新类别。
CategoricalIndex.remove_categories(*args, ...) 删除指定的类别。
CategoricalIndex.remove_unused_categories(...) 删除未使用的类别。
CategoricalIndex.set_categories(*args, **kwargs) 将分类设置为指定的新类别。
CategoricalIndex.as_ordered(*args, **kwargs) 将分类设置为有序。
CategoricalIndex.as_unordered(*args, **kwargs) 将分类索引设置为无序。

修改和计算

CategoricalIndex.map(mapper[, na_action]) 使用输入映射或函数映射值。
CategoricalIndex.equals(other) 确定两个分类索引对象是否包含相同的元素。

IntervalIndex

IntervalIndex(data[, closed, dtype, copy, ...]) 不可变的区间索引,其边界在同一侧关闭。

IntervalIndex 组件

IntervalIndex.from_arrays(left, right[, ...]) 从定义左右边界的两个数组构造。
IntervalIndex.from_tuples(data[, closed, ...]) 从元组的类数组构造 IntervalIndex。
IntervalIndex.from_breaks(breaks[, closed, ...]) 从拆分数组构造 IntervalIndex。
IntervalIndex.left
IntervalIndex.right
IntervalIndex.mid
IntervalIndex.closed 描述间隔的包含侧的字符串。
IntervalIndex.length
IntervalIndex.values 返回表示索引中数据的数组。
IntervalIndex.is_empty 表示区间是否为空,即不包含任何点。
IntervalIndex.is_non_overlapping_monotonic 返回一个布尔值,指示 IntervalArray 是否不重叠且单调。
IntervalIndex.is_overlapping 如果 IntervalIndex 存在重叠的区间,则返回 True,否则返回 False。
IntervalIndex.get_loc(key) 获取请求标签的整数位置、切片或布尔掩码。
IntervalIndex.get_indexer(target[, method, ...]) 给定当前索引,计算新索引的索引器和掩码。
IntervalIndex.set_closed(*args, **kwargs) 返回一个在指定侧关闭的相同 IntervalArray。
IntervalIndex.contains(*args, **kwargs) 逐个元素检查区间是否包含该值。
IntervalIndex.overlaps(*args, **kwargs) 逐个元素检查区间是否与 IntervalArray 中的值重叠。
IntervalIndex.to_tuples(*args, **kwargs) 返回形式为(左边界,右边界)的元组的 ndarray(如果 self 是 IntervalArray)或索引(如果 self 是 IntervalIndex)。

区间索引组件

IntervalIndex.from_arrays(left, right[, ...]) 通过定义左右边界的两个数组构造。
IntervalIndex.from_tuples(data[, closed, ...]) 从类似元组的数组构造 IntervalIndex。
IntervalIndex.from_breaks(breaks[, closed, ...]) 从分割数组构造 IntervalIndex。
IntervalIndex.left
IntervalIndex.right
IntervalIndex.mid
IntervalIndex.closed 描述区间的包含侧的字符串。
IntervalIndex.length
IntervalIndex.values 返回表示索引中数据的数组。
IntervalIndex.is_empty 指示区间是否为空,即它不包含任何点。
IntervalIndex.is_non_overlapping_monotonic 返回一个布尔值,指示 IntervalArray 是否非重叠且单调。
IntervalIndex.is_overlapping 如果 IntervalIndex 具有重叠的区间,则返回 True,否则返回 False。
IntervalIndex.get_loc(key) 获取所请求标签的整数位置、切片或布尔掩码。
IntervalIndex.get_indexer(target[, method, ...]) 给定当前索引,计算新索引的索引器和掩码。
IntervalIndex.set_closed(*args, **kwargs) 返回一个相同的 IntervalArray,其闭合在指定侧。
IntervalIndex.contains(*args, **kwargs) 逐个元素检查区间是否包含该值。
IntervalIndex.overlaps(*args, **kwargs) 逐个元素检查一个区间是否与 IntervalArray 中的值重叠。
IntervalIndex.to_tuples(*args, **kwargs) 返回形式为 (left, right) 的元组的 ndarray(如果 self 是 IntervalArray)或索引(如果 self 是 IntervalIndex)。

MultiIndex

MultiIndex([levels, codes, sortorder, ...]) 一个用于 pandas 对象的多级别(层次化)索引对象。

MultiIndex 构造器

MultiIndex.from_arrays(arrays[, sortorder, ...]) 将数组转换为 MultiIndex。
MultiIndex.from_tuples(tuples[, sortorder, ...]) 将元组列表转换为 MultiIndex。
MultiIndex.from_product(iterables[, ...]) 从多个可迭代对象的笛卡尔积创建一个 MultiIndex。
MultiIndex.from_frame(df[, sortorder, names]) 从 DataFrame 创建一个 MultiIndex。

MultiIndex 属性

MultiIndex.names MultiIndex 中级别的名称。
MultiIndex.levels MultiIndex 的级别。
MultiIndex.codes
MultiIndex.nlevels 这个 MultiIndex 中的级别数目(整数)。
MultiIndex.levshape 每个级别的长度的元组。
MultiIndex.dtypes 返回底层 MultiIndex 的 dtypes 作为 Series。

MultiIndex 组件

MultiIndex.set_levels(levels, *[, level, ...]) 在 MultiIndex 上设置新的级别。
MultiIndex.set_codes(codes, *[, level, ...]) 在 MultiIndex 上设置新的代码。
MultiIndex.to_flat_index() 将 MultiIndex 转换为包含级别值的元组的索引。
MultiIndex.to_frame([index, name, ...]) 使用 MultiIndex 的级别创建一个 DataFrame,级别将作为列。
MultiIndex.sortlevel([level, ascending, ...]) 在请求的级别上对 MultiIndex 进行排序。
MultiIndex.droplevel([level]) 返回删除请求的级别的索引。
MultiIndex.swaplevel([i, j]) 交换级别 i 和级别 j。
MultiIndex.reorder_levels(order) 使用输入顺序重新排列级别。
MultiIndex.remove_unused_levels() 从当前中创建新的 MultiIndex,删除未使用的级别。
MultiIndex.drop(codes[, level, errors]) 使用传递的代码列表创建一个新的 pandas.MultiIndex 删除的索引。
MultiIndex.copy([names, deep, name]) 创建此对象的副本。
MultiIndex.append(other) 将一系列索引选项附加在一起。
MultiIndex.truncate([before, after]) 在两个标签/元组之间切片索引,返回新的 MultiIndex。

多级索引选择

MultiIndex.get_loc(key) 获取标签或标签元组的位置。
MultiIndex.get_locs(seq) 获取标签序列的位置。
MultiIndex.get_loc_level(key[, level, ...]) 获取所请求标签/级别的位置和切片索引。
MultiIndex.get_indexer(target[, method, ...]) 针对当前索引计算新索引的索引器和掩码。
MultiIndex.get_level_values(level) 返回所请求级别的标签值向量。
IndexSlice 创建一个对象,更容易执行多级索引切片。

MultiIndex 构造器

MultiIndex.from_arrays(arrays[, sortorder, ...]) 将数组转换为 MultiIndex。
MultiIndex.from_tuples(tuples[, sortorder, ...]) 将元组列表转换为 MultiIndex。
MultiIndex.from_product(iterables[, ...]) 从多个可迭代对象的笛卡尔积中创建 MultiIndex。
MultiIndex.from_frame(df[, sortorder, names]) 从 DataFrame 创建 MultiIndex。

MultiIndex 属性

MultiIndex.names MultiIndex 中级别的名称。
MultiIndex.levels MultiIndex 的级别。
MultiIndex.codes
MultiIndex.nlevels 此 MultiIndex 中级别的整数数量。
MultiIndex.levshape 包含每个级别长度的元组。
MultiIndex.dtypes 返回基础 MultiIndex 的 dtypes 作为 Series。

MultiIndex 组件

MultiIndex.set_levels(levels, *[, level, ...]) 设置 MultiIndex 的新级别。
MultiIndex.set_codes(codes, *[, level, ...]) 设置 MultiIndex 的新代码。
MultiIndex.to_flat_index() 将 MultiIndex 转换为包含级别值的元组的索引。
MultiIndex.to_frame([index, name, ...]) 创建一个以 MultiIndex 级别为列的 DataFrame。
MultiIndex.sortlevel([level, ascending, ...]) 在请求的级别上对 MultiIndex 进行排序。
MultiIndex.droplevel([level]) 返回删除了请求级别的索引。
MultiIndex.swaplevel([i, j]) 交换级别 i 和级别 j。
MultiIndex.reorder_levels(order) 使用输入顺序重新排列级别。
MultiIndex.remove_unused_levels() 从当前索引创建新的 MultiIndex,删除未使用的级别。
MultiIndex.drop(codes[, level, errors]) 使用传递的代码列表创建一个新的pandas.MultiIndex,其中包含被删除的代码。
MultiIndex.copy([names, deep, name]) 复制此对象。
MultiIndex.append(other) 将一系列索引选项追加在一起。
MultiIndex.truncate([before, after]) 在两个标签/元组之间切片索引,返回新的 MultiIndex。

选择多重索引

MultiIndex.get_loc(key) 获取标签或标签元组的位置。
MultiIndex.get_locs(seq) 获取一系列标签的位置。
MultiIndex.get_loc_level(key[, level, ...]) 获取请求的标签/级别的位置和切片索引。
MultiIndex.get_indexer(target[, method, ...]) 根据当前索引计算新索引的索引器和掩码。
MultiIndex.get_level_values(level) 返回请求级别的标签值向量。
IndexSlice 创建一个对象,更容易执行多级索引切片。

DatetimeIndex

DatetimeIndex([data, freq, tz, normalize, ...]) 不可变的类似 ndarray 的 datetime64 数据。

时间/日期组件

DatetimeIndex.year 日期的年份。
DatetimeIndex.month 月份,一月为 1,十二月为 12。
DatetimeIndex.day 日期的日部分。
DatetimeIndex.hour 日期的小时部分。
DatetimeIndex.minute 日期的分钟部分。
DatetimeIndex.second 日期的秒部分。
DatetimeIndex.microsecond 日期的微秒部分。
DatetimeIndex.nanosecond 日期的纳秒部分。
DatetimeIndex.date 返回 python datetime.date 对象的 numpy 数组。
DatetimeIndex.time 返回 python datetime.time 对象的 numpy 数组。
DatetimeIndex.timetz 返回带有时区的 python datetime.time 对象的 numpy 数组。
DatetimeIndex.dayofyear 年份中的第几天。
DatetimeIndex.day_of_year 年份中的第几天。
DatetimeIndex.dayofweek 表示一周中的第几天,星期一为 0,星期日为 6。
DatetimeIndex.day_of_week 表示一周中的第几天,星期一为 0,星期日为 6。
DatetimeIndex.weekday 表示一周中的第几天,星期一为 0,星期日为 6。
DatetimeIndex.quarter 日期所在的季度。
DatetimeIndex.tz 返回时区。
DatetimeIndex.freq
DatetimeIndex.freqstr 如果设置了频率对象,则返回字符串,否则返回 None。
DatetimeIndex.is_month_start 表示日期是否为月初。
DatetimeIndex.is_month_end 表示日期是否为月底。
DatetimeIndex.is_quarter_start 指示日期是否为季度的第一天。
DatetimeIndex.is_quarter_end 指示日期是否为季度的最后一天。
DatetimeIndex.is_year_start 表示日期是否为一年的第一天。
DatetimeIndex.is_year_end 表示日期是否为一年的最后一天。
DatetimeIndex.is_leap_year 如果日期属于闰年,则返回布尔指示符。
DatetimeIndex.inferred_freq 尝试返回由 infer_freq 生成的表示频率的字符串。

选择

DatetimeIndex.indexer_at_time(time[, asof]) 返回特定时间的值的索引位置。
DatetimeIndex.indexer_between_time(...[, ...]) 返回特定时间段内值的索引位置。

时间特定操作

DatetimeIndex.normalize(*args, **kwargs) 将时间转换为午夜。
DatetimeIndex.strftime(date_format) 使用指定的 date_format 转换为索引。
DatetimeIndex.snap([freq]) 将时间戳捕捉到最近发生的频率。
DatetimeIndex.tz_convert(tz) 将具有时区信息的日期时间数组/索引从一个时区转换为另一个时区。
DatetimeIndex.tz_localize(tz[, ambiguous, ...]) 将没有时区信息的日期时间数组/索引本地化为具有时区信息的日期时间数组/索引。
DatetimeIndex.round(*args, **kwargs) 对数据执行四舍五入操作到指定的频率。
DatetimeIndex.floor(*args, **kwargs) 对数据执行向下取整操作到指定的频率。
DatetimeIndex.ceil(*args, **kwargs) 对数据执行向上取整操作到指定的频率。
DatetimeIndex.month_name(*args, **kwargs) 返回指定语言环境下的月份名称。
DatetimeIndex.day_name(*args, **kwargs) 返回指定语言环境下的星期几名称。

转换

DatetimeIndex.as_unit(*args, **kwargs) 转换为具有给定单位分辨率的 dtype。
DatetimeIndex.to_period(*args, **kwargs) 将数组转换为特定频率的 PeriodArray/PeriodIndex。
DatetimeIndex.to_pydatetime(*args, **kwargs) 返回一个 datetime.datetime 对象的 ndarray。
DatetimeIndex.to_series([index, name]) 创建一个 Series,索引和值都等于索引键。
DatetimeIndex.to_frame([index, name]) 创建一个 DataFrame,其中包含一个包含索引的列。

方法

DatetimeIndex.mean(*[, skipna, axis]) 返回数组的平均值。
DatetimeIndex.std(*args, **kwargs) 沿请求的轴返回样本标准差。

时间/日期组件

DatetimeIndex.year 日期时间的年份。
DatetimeIndex.month 月份,一月=1,十二月=12。
DatetimeIndex.day 日期时间的日期。
DatetimeIndex.hour 日期时间的小时数。
DatetimeIndex.minute 日期时间的分钟数。
DatetimeIndex.second 日期时间的秒数。
DatetimeIndex.microsecond 日期时间的微秒。
DatetimeIndex.nanosecond 日期时间的纳秒。
DatetimeIndex.date 返回 python datetime.date对象的 numpy 数组。
DatetimeIndex.time 返回datetime.time对象的 numpy 数组。
DatetimeIndex.timetz 返回带有时区的datetime.time对象的 numpy 数组。
DatetimeIndex.dayofyear 一年中的序数日期。
DatetimeIndex.day_of_year 一年中的序数日期。
DatetimeIndex.dayofweek 一周中的日期,星期一=0,星期日=6。
DatetimeIndex.day_of_week 一周中的日期,星期一=0,星期日=6。
DatetimeIndex.weekday 一周中的日期,星期一=0,星期日=6。
DatetimeIndex.quarter 日期所在季度。
DatetimeIndex.tz 返回时区。
DatetimeIndex.freq
DatetimeIndex.freqstr 如果设置了频率对象,则返回字符串,否则返回 None。
DatetimeIndex.is_month_start 表示日期是否为月初。
DatetimeIndex.is_month_end 表示日期是否为月末。
DatetimeIndex.is_quarter_start 表示日期是否为季度初。
DatetimeIndex.is_quarter_end 表示日期是否为季度末。
DatetimeIndex.is_year_start 表示日期是否为年初。
DatetimeIndex.is_year_end 表示日期是否为年底。
DatetimeIndex.is_leap_year 如果日期属于闰年,则返回布尔指示符。
DatetimeIndex.inferred_freq 尝试返回由 infer_freq 生成的表示频率的字符串。

选择

DatetimeIndex.indexer_at_time(time[, asof]) 返回特定时间的值的索引位置。
DatetimeIndex.indexer_between_time(...[, ...]) 返回在一天中特定时间之间的值的索引位置。

特定时间操作

DatetimeIndex.normalize(*args, **kwargs) 将时间转换为午夜。
DatetimeIndex.strftime(date_format) 使用指定的日期格式转换为索引。
DatetimeIndex.snap([freq]) 将时间戳捕捉到最近的发生频率。
DatetimeIndex.tz_convert(tz) 将具有时区信息的日期时间数组/索引从一个时区转换为另一个时区。
DatetimeIndex.tz_localize(tz[, ambiguous, ...]) 将时区无关的日期时间数组/索引本地化为具有时区信息的日期时间数组/索引。
DatetimeIndex.round(*args, **kwargs) 对数据执行舍入操作到指定的频率。
DatetimeIndex.floor(*args, **kwargs) 对数据执行向下取整操作到指定的频率。
DatetimeIndex.ceil(*args, **kwargs) 对数据执行向上取整操作到指定的频率。
DatetimeIndex.month_name(*args, **kwargs) 返回指定语言环境下的月份名称。
DatetimeIndex.day_name(*args, **kwargs) 返回指定语言环境下的星期几名称。

转换

DatetimeIndex.as_unit(*args, **kwargs) 转换为具有给定单位分辨率的 dtype。
DatetimeIndex.to_period(*args, **kwargs) 转换为特定频率的 PeriodArray/PeriodIndex。
DatetimeIndex.to_pydatetime(*args, **kwargs) 返回一个datetime.datetime对象的 ndarray。
DatetimeIndex.to_series([index, name]) 创建一个 Series,其索引和值都等于索引键。
DatetimeIndex.to_frame([index, name]) 创建一个包含索引的列的 DataFrame。

方法

DatetimeIndex.mean(*[, skipna, axis]) 返回数组的平均值。
DatetimeIndex.std(*args, **kwargs) 返回所请求轴上的样本标准差。

TimedeltaIndex

TimedeltaIndex([data, unit, freq, closed, ...]) 不可变 timedelta64 数据的索引。

组件

TimedeltaIndex.days 每个元素的天数。
TimedeltaIndex.seconds 每个元素的秒数(大于等于 0 且小于 1 天)。
TimedeltaIndex.microseconds 每个元素的微秒数(大于等于 0 且小于 1 秒)。
TimedeltaIndex.nanoseconds 每个元素的纳秒数(大于等于 0 且小于 1 微秒)。
TimedeltaIndex.components 返回 Timedeltas 的各个分辨率组件的 DataFrame。
TimedeltaIndex.inferred_freq 尝试返回由 infer_freq 生成的表示频率的字符串。

转换

TimedeltaIndex.as_unit(unit) 转换为具有给定单位分辨率的 dtype。
TimedeltaIndex.to_pytimedelta(*args, **kwargs) 返回一个 datetime.timedelta 对象的 ndarray。
TimedeltaIndex.to_series([index, name]) 创建一个 Series,其索引和值都等于索引键。
TimedeltaIndex.round(*args, **kwargs) 对数据执行四舍五入到指定频率的操作。
TimedeltaIndex.floor(*args, **kwargs) 对数据执行向下取整到指定频率的操作。
TimedeltaIndex.ceil(*args, **kwargs) 对数据执行向上取整到指定频率的操作。
TimedeltaIndex.to_frame([index, name]) 创建一个包含索引的列的 DataFrame。

方法

TimedeltaIndex.mean(*[, skipna, axis]) 返回数组的平均值。

组件

TimedeltaIndex.days 每个元素的天数。
TimedeltaIndex.seconds 每个元素的秒数(>= 0 且小于 1 天)。
TimedeltaIndex.microseconds 每个元素的微秒数(>= 0 且小于 1 秒)。
TimedeltaIndex.nanoseconds 每个元素的纳秒数(>= 0 且小于 1 微秒)。
TimedeltaIndex.components 返回 Timedeltas 的各个分辨率组件的 DataFrame。
TimedeltaIndex.inferred_freq 尝试返回由 infer_freq 生成的表示频率的字符串。

转换

TimedeltaIndex.as_unit(unit) 转换为具有给定单位分辨率的 dtype。
TimedeltaIndex.to_pytimedelta(*args, **kwargs) 返回一个包含 datetime.timedelta 对象的 ndarray。
TimedeltaIndex.to_series([index, name]) 创建一个索引和值都等于索引键的 Series。
TimedeltaIndex.round(*args, **kwargs) 对数据执行四舍五入操作到指定的频率。
TimedeltaIndex.floor(*args, **kwargs) 对数据执行向下取整操作到指定的频率。
TimedeltaIndex.ceil(*args, **kwargs) 对数据执行向上取整操作到指定的频率。
TimedeltaIndex.to_frame([index, name]) 创建一个包含索引的列的 DataFrame。

方法

TimedeltaIndex.mean(*[, skipna, axis]) 返回数组的平均值。

PeriodIndex

PeriodIndex([data, ordinal, freq, dtype, ...]) 不可变的 ndarray,包含指示时间中常规周期的序数值。

属性

PeriodIndex.day 周期的天数。
PeriodIndex.dayofweek 一周中的日期,星期一=0,星期日=6。
PeriodIndex.day_of_week 一周中的日期,星期一=0,星期日=6。
PeriodIndex.dayofyear 年中的序数天数。
PeriodIndex.day_of_year 年中的序数天数。
PeriodIndex.days_in_month 月份中的天数。
PeriodIndex.daysinmonth 月份中的天数。
PeriodIndex.end_time 获取周期结束的时间戳。
PeriodIndex.freq
PeriodIndex.freqstr 如果设置了频率对象,则返回字符串,否则返回 None。
PeriodIndex.hour 期间的小时数。
PeriodIndex.is_leap_year 逻辑指示日期是否属于闰年。
PeriodIndex.minute 期间的分钟数。
PeriodIndex.month 月份,一月为 1,十二月为 12。
PeriodIndex.quarter 日期的季度。
PeriodIndex.qyear
PeriodIndex.second 期间的秒数。
PeriodIndex.start_time 获取期间开始的时间戳。
PeriodIndex.week 年份的周序数。
PeriodIndex.weekday 一周的第几天,星期一为 0,星期日为 6。
PeriodIndex.weekofyear 年份的周序数。
PeriodIndex.year 期间的年份。

方法

PeriodIndex.asfreq([freq, how]) 将 PeriodArray 转换为指定频率 freq。
PeriodIndex.strftime(*args, **kwargs) 使用指定的日期格式转换为索引。
PeriodIndex.to_timestamp([freq, how]) 转换为 DatetimeArray/Index。
PeriodIndex.from_fields(*[, year, quarter, ...])
PeriodIndex.from_ordinals(ordinals, *, freq)

属性

PeriodIndex.day 期间的天数。
PeriodIndex.dayofweek 周几,星期一为 0,星期日为 6。
PeriodIndex.day_of_week 周几,星期一为 0,星期日为 6。
PeriodIndex.dayofyear 一年中的序数日期。
PeriodIndex.day_of_year 一年中的序数日期。
PeriodIndex.days_in_month 月份中的天数。
PeriodIndex.daysinmonth 月份中的天数。
PeriodIndex.end_time 获取周期结束时的时间戳。
PeriodIndex.freq
PeriodIndex.freqstr 如果已设置,返回频率对象的字符串,否则返回 None。
PeriodIndex.hour 周期的小时数。
PeriodIndex.is_leap_year 逻辑值,表示日期是否属于闰年。
PeriodIndex.minute 周期的分钟数。
PeriodIndex.month 月份,一月为 1,十二月为 12。
PeriodIndex.quarter 日期的季度。
PeriodIndex.qyear
PeriodIndex.second 周期的秒数。
PeriodIndex.start_time 获取周期开始时的时间戳。
PeriodIndex.week 年中的周序数。
PeriodIndex.weekday 一周中的日期,星期一=0,星期日=6。
PeriodIndex.weekofyear 一年中的周序数。
PeriodIndex.year 该时期的年份。

方法

PeriodIndex.asfreq([freq, how]) 将 PeriodArray 转换为指定频率 freq。
PeriodIndex.strftime(*args, **kwargs) 使用指定的日期格式转换为索引。
PeriodIndex.to_timestamp([freq, how]) 转换为 DatetimeArray/Index。
PeriodIndex.from_fields(*[, year, quarter, ...])
PeriodIndex.from_ordinals(ordinals, *, freq)
posted @   绝不原创的飞龙  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
历史上的今天:
2021-06-24 如何评价「施一公请辞清华大学副校长,全职执掌西湖大学」?你如何看待西湖大学的发展前景?
点击右上角即可分享
微信分享提示