python下的Pandas中DataFrame基本操作(一),基本函数整理

本文介绍了Pandas中的DataFrame数据结构,涵盖构造、属性、类型转换、索引迭代、二元运算等核心操作。此外,还讨论了函数应用、分组、窗口函数、描述统计、缺失值处理、数据合并以及时间序列分析等内容,为数据处理提供全面指导。

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

pandas作者Wes McKinney 在【PYTHON FOR DATA ANALYSIS】中对pandas的方方面面都有了一个权威简明的入门级的介绍,谈到pandas数据的行更新、表合并等操作,一般用到的方法有concat、join、merge。但这三种方法对于很多新手来说,都不太好分清使用的场合与用途。

构造函数

方法 描述
DataFrame([data, index, columns, dtype, copy]) 构造数据框

属性和数据

方法 描述
Axes index: row labels;columns: column labels
DataFrame.as_matrix([columns]) 转换为矩阵
DataFrame.dtypes 返回数据的类型
DataFrame.ftypes Return the ftypes (indication of sparse/dense and dtype) in this object.
DataFrame.get_dtype_counts() 返回数据框数据类型的个数
DataFrame.get_ftype_counts() Return the counts of ftypes in this object.
DataFrame.select_dtypes([include, exclude]) 根据数据类型选取子数据框
DataFrame.values Numpy的展示方式
DataFrame.axes 返回横纵坐标的标签名
DataFrame.ndim 返回数据框的纬度
DataFrame.size 返回数据框元素的个数
DataFrame.shape 返回数据框的形状
DataFrame.memory_usage([index, deep]) Memory usage of DataFrame columns.

类型转换

方法 描述
DataFrame.astype(dtype[, copy, errors]) 转换数据类型
DataFrame.copy([deep]) 复制数据框
DataFrame.isnull() 以布尔的方式返回空值
DataFrame.notnull() 以布尔的方式返回非空值

索引和迭代

方法 描述
DataFrame.head([n]) 返回前n行数据
DataFrame.at 快速标签常量访问器
DataFrame.iat 快速整型常量访问器
DataFrame.loc 标签定位
DataFrame.iloc 整型定位
DataFrame.insert(loc, column, value[, …]) 在特殊地点插入行
DataFrame.iter() Iterate over infor axis
DataFrame.iteritems() 返回列名和序列的迭代器
DataFrame.iterrows() 返回索引和序列的迭代器
DataFrame.itertuples([index, name]) Iterate over DataFrame rows as namedtuples, with index value as first element of the tuple.
DataFrame.lookup(row_labels, col_labels) Label-based “fancy indexing” function for DataFrame.
DataFrame.pop(item) 返回删除的项目
DataFrame.tail([n]) 返回最后n行
DataFrame.xs(key[, axis, level, drop_level]) Returns a cross-section (row(s) or column(s)) from the Series/DataFrame.
DataFrame.isin(values) 是否包含数据框中的元素
DataFrame.where(cond[, other, inplace, …]) 条件筛选
DataFrame.mask(cond[, other, inplace, axis, …]) Return an object of same shape as self and whose corresponding entries are from self where cond is False and otherwise are from other.
DataFrame.query(expr[, inplace]) Query the columns of a frame with a boolean expression.

二元运算

方法 描述
DataFrame.add(other[, axis, level, fill_value]) 加法,元素指向
DataFrame.sub(other[, axis, level, fill_value]) 减法,元素指向
DataFrame.mul(other[, axis, level, fill_value]) 乘法,元素指向
DataFrame.div(other[, axis, level, fill_value]) 小数除法,元素指向
DataFrame.truediv(other[, axis, level, …]) 真除法,元素指向
DataFrame.floordiv(other[, axis, level, …]) 向下取整除法,元素指向
DataFrame.mod(other[, axis, level, fill_value]) 模运算,元素指向
DataFrame.pow(other[, axis, level, fill_value]) 幂运算,元素指向
DataFrame.radd(other[, axis, level, fill_value]) 右侧加法,元素指向
DataFrame.rsub(other[, axis, level, fill_value]) 右侧减法,元素指向
DataFrame.rmul(other[, axis, level, fill_value]) 右侧乘法,元素指向
DataFrame.rdiv(other[, axis, l
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值