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 |