Pandas API参考

这篇内容介绍了Pandas的API参考,包括公共对象、函数和方法。提供了官方文档链接以获取详细信息,涉及到的子包如errors、plotting、testing等也有所提及。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文为谷歌翻译,有些翻译不准确 请参考原文档

http://pandas.pydata.org/pandas-docs/stable/api.html

此页面概述了所有公共pandas对象,函数和方法。 pandas。* namespace中公开的所有类和函数都是公共的。

一些子包是公共的,包括pandas.errors,pandas.plotting和pandas.testing。 文档中提到了pandas.io和pandas.tseries子模块中的公共函数。 pandas.api.types子包包含一些与pandas中的数据类型相关的公共函数。

Pickling

read_pickle(path[,compression])   从文件加载pickled pandas对象(或任何对象)。
Flat File

read_table(filepath_or_buffer[, sep, …])	将常规分隔文件读入DataFrame
read_csv(filepath_or_buffer[, sep, …])	将CSV(逗号分隔)文件读入DataFrame
read_fwf(filepath_or_buffer[, colspecs, widths])	将固定宽度格式化的行表读入DataFrame
read_msgpack(path_or_buf[, encoding, iterator])	从指定的文件路径加载msgpack pandas对象
Clipboard

read_clipboard([sep])	从剪贴板中读取文本并传递给read_table
Excel

read_excel(io[, sheet_name, header, names, …])	将Excel表读入pandas DataFrame
ExcelFile.parse([sheet_name, header, names, …])	将指定的工作表解析为DataFrame
JSON

read_json([path_or_buf, orient, typ, dtype, …])	将JSON字符串转换为pandas对象
json_normalize(data[, record_path, meta, …])	将“半结构化JSON数据”“规范化”为平面表
build_table_schema(data[, index, …])	从数据创建表模式。
HTML¶

read_html(io[, match, flavor, header, …])	将HTML表读入DataFrame对象列表。
HDFStore: PyTables (HDF5)

read_hdf(path_or_buf[, key, mode])	从商店读取,如果我们打开它关闭它。
HDFStore.put(key, value[, format, append])	将对象存储在HDFStore中
HDFStore.append(key, value[, format, …])	附加到文件中的表。
HDFStore.get(key)	检索存储在文件中的pandas对象
HDFStore.select(key[, where, start, stop, …])	检索存储在文件中的pandas对象,可选择基于where条件
HDFStore.info()	打印详细信息
HDFStore.keys()	返回与HDFStore中存储的对象相对应的键(可能无序)列表。
Feather

read_feather(path[, nthreads])	从文件路径加载羽毛格式对象
Parquet

read_parquet(path[, engine, columns])	从文件路径加载镶木地板对象,返回DataFrame。
SAS

read_sas(filepath_or_buffer[, format, …])	读取存储为XPORT或SAS7BDAT格式文件的SAS文件。
SQL

read_sql_table(table_name, con[, schema, …])	将SQL数据库表读入DataFrame。
read_sql_query(sql, con[, index_col, …])	将SQL查询读入DataFrame。
read_sql(sql, con[, index_col, …])	将SQL查询或数据库表读入DataFrame。
Google BigQuery

read_gbq(query[, project_id, index_col, …])	从Google BigQuery加载数据。
STATA

read_stata(filepath_or_buffer[, …])	将Stata文件读入DataFrame。
StataReader.data(**kwargs)	(已弃用)从Stata文件中读取观察结果,将其转换为数据帧
StataReader.data_label()	返回Stata文件的数据标签
StataReader.value_labels()	返回一个dict,将每个变量名称与一个dict相关联,将每个值与其对应的标签相关联
StataReader.variable_labels()	将变量标签作为dict返回,将每个变量名称与相应的标签相关联
StataWriter.write_file()	
General functions¶
Data manipulations

melt(frame[, id_vars, value_vars, var_name, …])	“Unpivots”DataFrame从宽格式到长格式,可选择设置标识符变量。
pivot(index, columns, values)	根据此DataFrame的3列生成“pivot”表。
pivot_table(data[, values, index, columns, …])	创建一个电子表格样式的数据透视表作为DataFrame。
crosstab(index, columns[, values, rownames, …])	计算两个(或更多)因子的简单交叉列表。
cut(x, bins[, right, labels, retbins, …])	Bin值为离散间隔。
qcut(x, q[, labels, retbins, precision, …])	基于分位数的离散化功能。
merge(left, right[, how, on, left_on, …])	通过按列或索引执行数据库样式的连接操作来合并DataFrame对象。
merge_ordered(left, right[, on, left_on, …])	使用为时序数据等有序数据设计的可选填充/插值执行合并。
merge_asof(left, right[, on, left_on, …])	执行asof合并。
concat(objs[, axis, join, join_axes, …])	沿特定轴连接pandas对象,沿其他轴使用可选的设置逻辑。
get_dummies(data[, prefix, prefix_sep, …])	将分类变量转换为虚拟/指示变量
factorize(values[, sort, order, …])	将对象编码为枚举类型或分类变量。
unique(values)	哈希表基于唯一。
wide_to_long(df, stubnames, i, j[, sep, suffix])	宽面板到长格式。
Top-level missing data

isna(obj)	检测类似数组的对象的缺失值。
isnull(obj)	检测类似数组的对象的缺失值。
notna(obj)	检测类似数组的对象的非缺失值。
notnull(obj)	检测类似数组的对象的非缺失值。
Top-level conversions

to_numeric(arg[, errors, downcast])	将参数转换为数字类型。
Top-level dealing with datetimelike

to_datetime(arg[, errors, dayfirst, …])	将参数转换为datetime。
to_timedelta(arg[, unit, box, errors])	将参数转换为timedelta
date_range([start, end, periods, freq, tz, …])	返回固定频率DatetimeIndex。
bdate_range([start, end, periods, freq, tz, …])	返回固定频率DatetimeIndex,以工作日作为默认频率
period_range([start, end, periods, freq, name])	返回固定频率PeriodIndex,以日(日历)作为默认频率
timedelta_range([start, end, periods, freq, …])	返回固定频率TimedeltaIndex,以day作为默认频率
infer_freq(index[, warn])	根据输入索引推断最可能的频率。
Top-level dealing with intervals

interval_range([start, end, periods, freq, …])	返回固定频率IntervalIndex
Top-level evaluation

eval(expr[, parser, engine, truediv, …])	使用各种后端将Python表达式评估为字符串。
Testing

test([extra_args])	
Series
Constructor

Series([data, index, dtype, name, copy, …])	带轴标签的一维ndarray(包括时间序列)。
Attributes
Axes

Series.index	系列的索引(轴标签)。
Series.values	返回系列为ndarray或ndarray-like取决于dtype
Series.dtype	返回基础数据的dtype对象
Series.ftype	如果数据稀疏则返回
Series.shape	返回基础数据形状的元组
Series.nbytes	返回基础数据中的字节数
Series.ndim	根据定义1,返回基础数据的维数
Series.size	返回基础数据中的元素数量
Series.strides	返回基础数据的步幅
Series.itemsize	返回基础数据项的dtype的大小
Series.base	如果共享基础数据的内存,则返回基础对象
Series.T	返回转置,根据定义自我
Series.memory_usage([index, deep])	返回Series的内存使用情况。
Series.hasnans	如果我有任何nans,我会回来; 实现各种性能加速
Series.flags	
Series.empty	
Series.dtypes	返回基础数据的dtype对象
Series.ftypes	如果数据稀疏则返回
Series.data	返回基础数据的数据指针
Series.is_copy	
Series.name	
Series.put(*args, **kwargs)	将put方法应用于其values属性(如果有)。
Conversion

Series.astype(dtype[, copy, errors])	将pandas对象转换为指定的dtype dtype。
Series.infer_objects()	尝试推断对象列的更好的dtypes。
Series.convert_objects([convert_dates, …])	(DEPRECATED)尝试推断对象列的更好dtype。
Series.copy([deep])	复制此对象的索引和数据。
Series.bool()	返回单个元素Pandas Object的书。
Series.to_period([freq, copy])	将Series从DatetimeIndex转换为具有所需频率的PeriodIndex(如果未传递,则从索引推断)
Series.to_timestamp([freq, how, copy])	在期间开始时转换为时间戳的datetimedex
Series.tolist()	返回值列表。
Series.get_values()	与值相同(但处理稀疏转换); 是一种观点
Indexing, iteration

Series.get(key[, default])	从给定键的对象获取项目(DataFrame列,Panel切片等)。
Series.at	访问行/列标签对的单个值。
Series.iat	按整数位置访问行/列对的单个值。
Series.loc	通过标签或布尔数组访问一组行和列。
Series.iloc	纯粹基于整数位置的索引,用于按位置选择。
Series.__iter__()	返回值的迭代器。
Series.iteritems()	懒惰地迭代(索引,值)元组
Series.items()	懒惰地迭代(索引,值)元组
Series.keys()	索引的别名
Series.pop(item)	返回项目并从框架中删除。
Series.item()	将基础数据的第一个元素作为python标量返回
Series.xs(key[, axis, level, drop_level])	返回Series / DataFrame的横截面(行或列)。
Binary operator functions

Series.add(other[, level, fill_value, axis])	添加系列和其他元素(二元运算符添加)。
Series.sub(other[, level, fill_value, axis])	减去序列和其他元素(二元运算符子)。
Series.mul(other[, level, fill_value, axis])	系列和其他的乘法,元素(二元运算符mul)。
Series.div(other[, level, fill_value, axis])	系列和其他的浮动划分,元素方式(二元算子truediv)。
Series.truediv(other[, level, fill_value, axis])	系列和其他的浮动划分,元素方式(二元算子truediv)。
Series.floordiv(other[, level, fill_value, axis])	系列和其他的整数除法,元素方式(二元运算符floordiv)。
Series.mod(other[, level, fill_value, axis])	系列和其他的模数,元素方式(二元运算符mod)。
Series.pow(other[, level, fill_value, axis])	系列和其他元素的指数幂(二元运算符pow)。
Series.radd(other[, level, fill_value, axis])	添加系列和其他元素(二元运算符radd)。
Series.rsub(other[, level, fill_value, axis])	减去序列和其他元素(二元运算符rsub)。
Series.rmul(other[, level, fill_value, axis])	系列和其他的乘法,元素(二元运算符rmul)。
Series.rdiv(other[, level, fill_value, axis])	系列和其他的浮动划分,元素方式(二元算子rtruediv)。
Series.rtruediv(other[, level, fill_value, axis])	系列和其他的浮动划分,元素方式(二元算子rtruediv)。
Series.rfloordiv(other[, level, fill_value, …])	系列和其他的整数除法,元素方式(二元运算符rfloordiv)。
Series.rmod(other[, level, fill_value, axis])	系列和其他的模数,元素方式(二元运算符rmod)。
Series.rpow(other[, level, fill_value, axis])	系列和其他元素的指数幂(二元运算符rpow)。
Series.combine(other, func[, fill_value])	当一个系列或另一个系列中缺少索引时,使用给定函数对两个系列执行元素二进制运算,并带有可选填充值
Series.combine_first(other)	组合系列值,首先选择调用Series的值。
Series.round([decimals])	将系列中的每个值舍入到给定的小数位数。
Series.lt(other[, level, fill_value, axis])	少于系列和其他元素(二元运算符lt)。
Series.gt(other[, level, fill_value, axis])	大于系列和其他元素(二元运算符gt)。
Series.le(other[, level, fill_value, axis])	小于或等于系列和其他元素(二元运算符文件)。
Series.ge(other[, level, fill_value, axis])	大于或等于系列和其他元素(二元运算符ge)。
Series.ne(other[, level, fill_value, axis])	不等于系列和其他元素(二元运算符ne)。
Series.eq(other[, level, fill_value, axis])	等于系列和其他元素(二元运算符eq)。
Series.product([axis, skipna, level, …])	返回请求轴的值的乘积
Series.dot(other)	矩阵乘法与DataFrame或内部产品与Series对象。
Function application, GroupBy & Window

Series.apply(func[, convert_dtype, args])	调用Series的值的函数。
Series.agg(func[, axis])	使用指定轴上的一个或多个操作进行聚合。
Series.aggregate(func[, axis])	使用指定轴上的一个或多个操作进行聚合。
Series.transform(func, *args, **kwargs)	调用函数生成类似索引的NDFrame并返回带有转换值的NDFrame
Series.map(arg[, na_action])	使用输入对应(字典,系列或函数)映射Series的值。
Series.groupby([by, axis, level, as_index, …])	使用mapper(dict或key函数,将给定函数应用于组,将结果作为系列返回)或通过一系列列的组系列。
Series.rolling(window [,min_periods,...])提供滚动窗口计算。
Series.expanding([min_periods, center, axis])	提供扩展转换。
Series.ewm([com, span, halflife, alpha, …])	提供指数加权函数
Series.pipe(func, *args, **kwargs)	应用func(self,* args,** kwargs)
Computations / Descriptive Stats

Series.abs()	返回具有每个元素的绝对数值的Series / DataFrame。
Series.all([axis, bool_only, skipna, level])	返回是否所有元素都是True,可能是在轴上。
Series.any([axis, bool_only, skipna, level])	返回任何元素在请求的轴上是否为True。
Series.autocorr([lag])	Lag-N自相关
Series.between(left, right[, inclusive])	返回boolean Series等效于left <= series <= right。
Series.clip([lower, upper, axis, inplace])	在输入阈值处修剪值。
Series.clip_lower(threshold[, axis, inplace])	返回值低于阈值截断的输入的副本。
Series.clip_upper(threshold[, axis, inplace])	输入的返回副本,其值超过给定值(截断)。
Series.corr(other[, method, min_periods])	计算与其他系列的相关性,不包括缺失值
Series.count([level])	返回系列中非NA / null观测值的返回数
Series.cov(other[, min_periods])	计算与Series的协方差,不包括缺失值
Series.cummax([axis, skipna])	返回DataFrame或Series轴上的累积最大值。
Series.cummin([axis, skipna])	返回DataFrame或Series轴上的累积最小值。
Series.cumprod([axis, skipna])	通过DataFrame或Series轴返回累积产品。
Series.cumsum([axis, skipna])	返回DataFrame或Series轴上的累积和。
Series.describe([percentiles, include, exclude])	生成描述性统计数据,总结数据集分布的集中趋势,分散和形状,不包括NaN值。
Series.diff([periods])	第一个离散的元素差异。
Series.factorize([sort, na_sentinel])	将对象编码为枚举类型或分类变量。
Series.kurt([axis, skipna, level, numeric_only])	使用Fisher对峰度的定义(正常峰度== 0.0),在请求轴上返回无偏峰度。
Series.mad([axis, skipna, level])	返回请求轴的值的平均绝对偏差
Series.max([axis, skipna, level, numeric_only])	此方法返回对象中的最大值。
Series.mean([axis, skipna, level, numeric_only])	返回请求轴的值的平均值
Series.median([axis, skipna, level, …])	返回请求轴的值的中值
Series.min([axis, skipna, level, numeric_only])	此方法返回对象中的最小值。
Series.mode()	返回数据集的模式。
Series.nlargest([n, keep])	返回最大的n个元素。
Series.nsmallest([n, keep])	返回最小的n个元素。
Series.pct_change([periods, fill_method, …])	当前元素和先前元素之间的百分比变化。
Series.prod([axis, skipna, level, …])	返回请求轴的值的乘积
Series.quantile([q, interpolation])	给定分位数处的返回值,即la numpy.percentile。
Series.rank([axis, method, numeric_only, …])	沿轴计算数值数据等级(1到n)。
Series.sem([axis, skipna, level, ddof, …])	在请求的轴上返回均值的无偏标准误差。
Series.skew([axis, skipna, level, numeric_only])	返回请求轴的无偏偏差,由N-1归一化
Series.std([axis, skipna, level, ddof, …])	返回请求轴上的样本标准偏差。
Series.sum([axis, skipna, level, …])	返回请求轴的值的总和
Series.var([axis, skipna, level, ddof, …])	在请求的轴上返回无偏差异。
Series.kurtosis([axis, skipna, level, …])	使用Fisher对峰度的定义(正常峰度== 0.0),在请求轴上返回无偏峰度。
Series.unique()	返回Series对象的唯一值。
Series.nunique([dropna])	返回对象中唯一元素的数量。
Series.is_unique	如果对象中的值是唯一的,则返回布尔值
Series.is_monotonic	如果对象中的值是monotonic_increasing,则返回布尔值
Series.is_monotonic_increasing	如果对象中的值是monotonic_increasing,则返回布尔值
Series.is_monotonic_decreasing	如果对象中的值是monotonic_decreasing,则返回布尔值
Series.value_counts([normalize, sort, …])	返回包含唯一值计数的对象。
Series.compound([axis, skipna, level])	返回请求轴的值的复合百分比
Series.nonzero()	返回非零元素的整数索引
Series.ptp([axis, skipna, level, numeric_only])	返回最大值和之间的差值
Reindexing / Selection / Label manipulation

Series.align(other[, join, axis, level, …])	使用指定的每个轴索引的连接方法将轴上的两个对象对齐
Series.drop([labels, axis, index, columns, …])	返回已删除指定索引标签的系列。
Series.drop_duplicates([keep, inplace])	返回系列,删除重复值。
Series.duplicated([keep])	指示重复的系列值。
Series.equals(other)	确定两个NDFrame对象是否包含相同的元素。
Series.first(offset)	用于基于日期偏移量化时间序列数据的初始时段的便捷方法。
Series.head([n])	返回前n行。
Series.idxmax([axis, skipna])	返回最大值的行标签。
Series.idxmin([axis, skipna])	返回最小值的行标签。
Series.isin(values)	检查系列中是否包含值。
Series.last(offset)	用于基于日期偏移量化时间序列数据的最终时段的便捷方法。
Series.reindex([index])	使用可选填充逻辑将系列符合到新索引,将NA / NaN放置在先前索引中没有值的位置。
Series.reindex_like(other[, method, copy, …])	将具有匹配索引的对象返回给我自己。
Series.rename([index])	更改系列索引标签或名称
Series.rename_axis(mapper[, axis, copy, inplace])	更改索引或列的名称。
Series.reset_index([level, drop, name, inplace])	使用索引重置生成新的DataFrame或Series。
Series.sample([n, frac, replace, weights, …])	从对象轴返回随机的项目样本。
Series.select(crit[, axis])	(DEPRECATED)返回与轴标签匹配条件对应的数据
Series.set_axis(labels[, axis, inplace])	将所需索引分配给给定轴。
Series.take(indices[, axis, convert, is_copy])	沿轴返回给定位置索引中的元素。
Series.tail([n])	返回最后n行。
Series.truncate([before, after, axis, copy])	在某个索引值之前和之后截断Series或DataFrame。
Series.where(cond[, other, inplace, axis, …])	返回与self相同形状的对象,其对应的条目来自self,其中cond为True,否则来自其他。
Series.mask(cond[, other, inplace, axis, …])	返回与self相同形状的对象,其对应的条目来自self,其中cond为False,否则来自other。
Series.add_prefix(prefix)	带有字符串前缀的前缀标签。
Series.add_suffix(suffix)	带有字符串后缀的后缀标签。
Series.filter([items, like, regex, axis])	根据指定索引中的标签设置数据框的行或列。
Missing data handling

Series.isna()	检测缺失值。
Series.notna()	检测现有(非缺失)值。
Series.dropna([axis, inplace])	返回删除了缺失值的新系列。
Series.fillna([value, method, axis, …])	使用指定的方法填充NA / NaN值
Series.interpolate([method, axis, limit, …])	根据不同的方法插值。
Reshaping, sorting

Series.argsort([axis, kind, order])	覆盖ndarray.argsort。
Series.argmin([axis, skipna])	(已弃用)..已弃用:: 0.21.0拆散,a.k.a。
Series.reorder_levels(order)	使用输入顺序重新排列索引级别。
Series.sort_values([axis, ascending, …])	按值排序。
Series.sort_index([axis, level, ascending, …])	按索引标签排序系列。
Series.swaplevel([i, j, copy])	在MultiIndex中交换i和j级别
Series.unstack([level, fill_value])	拆散,a.k.a。
Series.searchsorted(value[, side, sorter])	查找应插入元素以维护顺序的索引。
Series.ravel([order])	将展平的底层数据作为ndarray返回
Series.repeat(repeats, *args, **kwargs)	重复系列的元素。
Series.squeeze([axis])	挤压长度1维。
Series.view([dtype])	创建系列的新视图。
Series.sortlevel([level, ascending, …])	(已弃用)按所选级别对MultiIndex排序系列。
Combining / joining / merging

Series.append(to_append[, ignore_index, …])	连接两个或更多系列。
Series.replace([to_replace, value, inplace, …])	用值替换to_replace中给出的值。
Series.update(other)	使用传递的Series中的非NA值修改系列。
Time series-related

Series.asfreq(freq[, method, how, …])	将TimeSeries转换为指定的频率。
Series.asof(where[, subset])	获取没有任何NaN的最后一行(或者在没有NaN的情况下考虑仅使用DataFrame情况下的列子集的最后一行)
Series.shift([periods, freq, axis])	使用可选的时间频率按期望的周期数移动索引
Series.first_valid_index()	返回第一个非NA / null值的索引。
Series.last_valid_index()	返回最后一个非NA / null值的索引。
Series.resample(rul
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值