pandas 类型别名#

类型别名#

中的类型声明pandas/_typing.py被认为是私有的,并由 pandas 开发人员用于对 pandas 代码库进行类型检查。对于用户,强烈建议使用pandas-stubs包,该包代表了对 pandas 用户官方支持的类型声明。此处记录它们是为了希望在调用 pandas 或期望特定结果的自己的 Python 代码中使用这些声明的用户。

警告

请注意,这些别名的定义和用例可能会在 pandas 的任何主要、次要或补丁版本中恕不另行通知而更改。

下表中列出的每个别名都可以通过从pandas.api.typing.aliases导入来找到。

别名

含义

AggFuncType

可以传递给agg()方法的函数的类型

AlignJoin

DataFrame.join()join的参数类型

AnyAll

dropna()how的参数类型

AnyArrayLike

用于表示ExtensionArraynumpy数组、IndexSeries

ArrayLike

用于表示ExtensionArraynumpy数组

AstypeArg

astype()中的参数类型

AnyArrayLike加上序列(非字符串)和range

Axis

许多方法中axis的参数类型

CSVEngine

DataFrame.read_csv()engine的参数类型

ColspaceArgType

DataFrame.to_html()colspace的参数类型

CompressionOptions

DataFrame.to_parquet()外的所有 I/O 输出方法中compression的参数类型

CorrelationMethod

corr()correlation的参数类型

DropKeep

drop_duplicates()keep的参数类型

Dtype

可用于指定 dtype 的类型对象

DtypeArg

各种方法中dtype的参数类型

DtypeBackend

各种方法中dtype_backend的参数类型

DtypeObj

Numpy dtypes 和 Extension dtypes

ExcelWriterIfSheetExists

ExcelWriterif_sheet_exists的参数类型

ExcelWriterMergeCells

to_excel()方法中merge_cells的参数类型

FilePath

I/O 方法的文件路径类型

FillnaOptions

在填充 NA 值的各种方法中,method的参数类型

FloatFormatType

to_string()方法中float_format的参数类型

FormattersType

to_string()方法中formatters的参数类型

FromDictOrient

DataFrame.from_dict()方法中orient的参数类型

HTMLFlavors

pandas.read_html()flavor的参数类型

IgnoreRaise

多个方法中errors的参数类型

IndexLabel

多个方法中level的参数类型

InterpolateOptions

interpolate()方法中interpolate的参数类型

JSONEngine

read_json()方法中engine的参数类型

JSONSerializable

to_json()中参数default_handler的可调用返回值的参数类型

JoinHow

pandas.merge_ordered()how的参数类型,以及Series.align()join的参数类型

JoinValidate

DataFrame.join()方法中validate的参数类型

MergeHow

merge()方法中how的参数类型

MergeValidate

merge()方法中validate的参数类型

NaPosition

sort_index()sort_values()方法中na_position的参数类型

NsmallestNlargestKeep

nlargest()nsmallest()方法中keep的参数类型

OpenFileErrors

to_hdf()to_csv()方法中errors的参数类型

Ordered

CategoricalDtypeCategoricalordered的返回值类型

ParquetCompressionOptions

DataFrame.to_parquet()方法中compression的参数类型

QuantileInterpolation

quantile()方法中interpolation的参数类型

ReadBuffer

各种文件读取方法对应的 buffer 的附加参数类型

ReadCsvBuffer

pandas.read_csv()对应的 buffer 的附加参数类型

ReadPickleBuffer

pandas.read_pickle()对应的 buffer 的附加参数类型

ReindexMethod

reindex()方法中reindex的参数类型

标量

可以存储在具有非 object dtype 的Series中的类型

SequenceNotStr

用于需要序列但非纯字符串的参数

SliceType

Index.slice_locs()方法中startend的参数类型

SortKind

sort_index()sort_values()方法中kind的参数类型

StorageOptions

各种文件输出方法中storage_options的参数类型

Suffixes

merge()compare()merge_ordered()方法中suffixes的参数类型

TakeIndexer

take()方法中indexerindices的参数类型

TimeAmbiguous

时间操作中ambiguous的参数类型

TimeGrouperOrigin

resample()方法和TimeGrouperorigin的参数类型

TimeNonexistent

时间操作中nonexistent的参数类型

TimeUnit

时间单位参数和unit的返回值类型,参数unitdate_unit

TimedeltaConvertibleTypes

resample()方法中offset的参数类型,ewm()方法中halflife的参数类型,以及pandas.timedelta_range()startend的参数类型

TimestampConvertibleTypes

resample()方法中origin的参数类型,以及pandas.to_datetime()origin的参数类型

ToStataByteorder

DataFrame.to_stata()方法中byteorder的参数类型

ToTimestampHow

to_timestamp()方法中how的参数类型,以及resample()方法中convention的参数类型

UpdateJoin

DataFrame.update()方法中join的参数类型

UsecolsArgType

pandas.read_clipboard()pandas.read_csv()pandas.read_excel()usecols的参数类型

WindowingRankType

在滚动和扩展窗口操作的rank()方法中,method的参数类型

WriteBuffer

各种文件输出方法对应的 buffer 的附加参数类型

WriteExcelBuffer

to_excel()方法对应的 buffer 的附加参数类型

XMLParsers

DataFrame.to_xml()pandas.read_xml()方法中parser的参数类型