pandas.DataFrame对象解析
pandas.DataFrame对象类型解析
df = pd.DataFrame([[1,"2",3,4],[5,"6",7,8]],columns=["a","b","c","d"])
method解析
1、add()方法:类似加法运算(相加的元素必须是同一对象的数据)
| add(self, other, axis='columns', level=None, fill_value=None)
| Addition of dataframe and other, element-wise (binary operator `add`).
|
| Equivalent to ``dataframe + other``, but with support to substitute a fill_value for
| missing data in one of the inputs.
|
| Parameters
| ----------
| other : Series, DataFrame, or constant
| axis : {0, 1, 'index', 'columns'}
| For Series input, axis to match Series index on
| level : int or name
| Broadcast across a level, matching Index values on the
| passed MultiIndex level
| fill_value : None or float value, default None
| Fill existing missing (NaN) values, and any new element needed for
| successful DataFrame alignment, with this value before computation.
| If data in both corresponding DataFrame locations is missing
| the result will be missing
pandas.DataFrame.add方法
example:
output:
2、aggregate()方法:可简写agg()方法
aggregate(self, func, axis=0, *args, **kwargs)
| Aggregate using one or more operations over the specified axis.
|
| .. versionadded:: 0.20.0
|
| Parameters
| ----------
| func : function, string, dictionary, or list of string/functions
| Function to use for aggregating the data. If a function, must either
| work when passed a DataFrame or when passed to DataFrame.apply. For
| a DataFrame, can pass a dict, if the keys are DataFrame column names.
|
| Accepted combinations are:
|
| - string function name.
| - function.
| - list of functions.
| - dict of column names -> functions (or list of functions).
pandas.DataFrame.aggregate方法
example:
#coding=utf-8
import pandas as pd
import numpy as np ds = pd.Series([11,"",13,14])
print ds,"\n" df = pd.DataFrame([[1,"",3,4],[5,"",7,8]],columns=["a","b","c","d"])
print df,"\n" print(df.agg(['sum', 'min']))
print(df.agg({"a":['sum', 'min']}))
output:
0 11
1 2
2 13
3 14
dtype: object a b c d
0 1 2 3 4
1 5 6 7 8 a b c d
sum 6 26 10 12
min 1 2 3 4
a
sum 6
min 1
常用的aggregation functions (`mean`, `median`, `prod`, `sum`, `std`,`var`)
mad(self, axis=None, skipna=None, level=None)
Return the mean absolute deviation of the values for the requested axis
max(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
This method returns the maximum of the values in the object.If you want the *index* of the maximum, use ``idxmax``. This is the equivalent of the ``numpy.ndarray`` method ``argmax``.
mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
Return the mean of the values for the requested axis
median(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
Return the median of the values for the requested axis
min(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
This method returns the minimum of the values in the object. memory_usage(self, index=True, deep=False)
Return the memory usage of each column in bytes.
merge(self, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=('_x', '_y'), copy=True, indicator=False, validate=None)
Merge DataFrame objects by performing a database-style join operation by columns or indexes.
align(self, other, join='outer', axis=None, level=None, copy=True, fill_value=None, method=None, limit=None, fill_axis=0, broadcast_axis=None):
Align two objects on their axes with the specified join method for each axis Index
all(self, axis=None, bool_only=None, skipna=None, level=None, **kwargs):
Return whether all elements are True over series or dataframe axis.
any(self, axis=None, bool_only=None, skipna=None, level=None, **kwargs):
Return whether any element is True over requested axis.
apply(self, func, axis=0, broadcast=None, raw=False, reduce=None, result_type=None, args=(), **kwds):
Apply a function along an axis of the DataFrame.
applymap(self, func):
Apply a function to a Dataframe elementwise.This method applies a function that accepts and returns a scalarto every element of a DataFrame.
append(self, other, ignore_index=False, verify_integrity=False, sort=None):
Append rows of `other` to the end of this frame, returning a new object. Columns not in this frame are added as new columns.
assign(self, **kwargs):
Assign new columns to a DataFrame, returning a new object(a copy) with the new columns added to the original ones.Existing columns that are re-assigned will be overwritten.
insert(self, loc, column, value, allow_duplicates=False)
Insert column into DataFrame at specified location. combine(self, other, func, fill_value=None, overwrite=True):
Add two DataFrame objects and do not propagate NaN values, so if for a(column, time) one frame is missing a value, it will default to theother frame's value (which might be NaN as well)
count(self, axis=0, level=None, numeric_only=False):
Count non-NA cells for each column or row.
cov(self, min_periods=None):
Compute pairwise covariance of columns, excluding NA/null values.
drop(self, labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise'):
Drop specified labels from rows or columns.
drop_duplicates(self, subset=None, keep='first', inplace=False):
Return DataFrame with duplicate rows removed, optionally onlyconsidering certain columns
dropna(self, axis=0, how='any', thresh=None, subset=None, inplace=False)
Remove missing values.
duplicated(self, subset=None, keep='first')
Return boolean Series denoting duplicate rows, optionally onlyconsidering certain columns
eq(self, other, axis='columns', level=None)
Wrapper for flexible comparison methods eq
eval(self, expr, inplace=False, **kwargs)
Evaluate a string describing operations on DataFrame columns.
fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)
Fill NA/NaN values using the specified method
ge(self, other, axis='columns', level=None)
Wrapper for flexible comparison methods ge
gt(self, other, axis='columns', level=None)
Wrapper for flexible comparison methods gt
le(self, other, axis='columns', level=None)
Wrapper for flexible comparison methods le
lt(self, other, axis='columns', level=None)
Wrapper for flexible comparison methods lt get_value(self, index, col, takeable=False)
Quickly retrieve single value at passed column and index
info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None)
Print a concise summary of a DataFrame.
isin(self, values)
Return boolean DataFrame showing whether each element in theDataFrame is contained in values.
isna(self)
Detect missing values.Return a boolean same-sized object indicating if the values are NA.
isnull(self)
Detect missing values.Return a boolean same-sized object indicating if the values are NA.
iteritems(self)
Iterator over (column name, Series) pairs.
iterrows(self)
Iterate over DataFrame rows as (index, Series) pairs.
itertuples(self, index=True, name='Pandas')
Iterate over DataFrame rows as namedtuples, with index value as firstelement of the tuple.
join(self, other, on=None, how='left', lsuffix='', rsuffix='', sort=False)
Join columns with other DataFrame either on index or on a keycolumn. Efficiently Join multiple DataFrame objects by index at once bypassing a list.
pandas.DataFrame对象解析的更多相关文章
- [Pandas技巧] 如何把pandas dataframe对象或series对象转换成list
import pandas as pd >>> df = pd.DataFrame({'a':[1,3,5,7,4,5,6,4,7,8,9], 'b':[3,5,6,2,4,6,7, ...
- 重拾Python(4):Pandas之DataFrame对象的使用
Pandas有两大数据结构:Series和DataFrame,之前已对Series对象进行了介绍(链接),本文主要对DataFrame对象的常用用法进行总结梳理. 约定: import pandas ...
- 将pandas的Dataframe对象读写Excel文件
Dataframe对象生成Excel文件 需要xlrd库 命令 pip install xlrd #导入pandas import pandas as pd import numpy as np ...
- pandas中DataFrame对象to_csv()方法中的encoding参数
当使用pd.read_csv()方法读取csv格式文件的时候,常常会因为csv文件中带有中文字符而产生字符编码错误,造成读取文件错误,在这个时候,我们可以尝试将pd.read_csv()函数的enco ...
- pandas.DataFrame学习系列1——定义及属性
定义: DataFrame是二维的.大小可变的.成分混合的.具有标签化坐标轴(行和列)的表数据结构.基于行和列标签进行计算.可以被看作是为序列对象(Series)提供的类似字典的一个容器,是panda ...
- pandas DataFrame apply()函数(1)
之前已经写过pandas DataFrame applymap()函数 还有pandas数组(pandas Series)-(5)apply方法自定义函数 pandas DataFrame 的 app ...
- python数据类型之pandas—DataFrame
DataFrame定义: DataFrame是pandas的两个主要数据结构之一,另一个是Series —一个表格型的数据结构 —含有一组有序的列 —大致可看成共享同一个index的Series集合 ...
- 【338】Pandas.DataFrame
Ref: Pandas Tutorial: DataFrames in Python Ref: pandas.DataFrame Ref: Pandas:DataFrame对象的基础操作 Ref: C ...
- pandas dataframe在指定的位置添加一列, 或者一次性添加几列,re
相信有很多人收这个问题的困扰,如果你想一次性在pandas.DataFrame里添加几列,或者在指定的位置添加一列,都会很苦恼找不到简便的方法:可以用到的函数有df.reindex, pd.conca ...
随机推荐
- 洛谷 P2341 [HAOI2006]受欢迎的牛 题解
今天学了强连通分量的Tarjan算法,做了这道类似于板子题的题(尽管我调了1.5h).主要的思路是用Tarjan缩点之后,求每个点的入度(实际上是出度,因为我是反着连边的).如果 有且只有一个点的入度 ...
- hibernate实现增删改查
1.需要先创建学生实体: package pers.zhb.domain; public class Student { private int studentno; private String s ...
- Linux常用命令合集
常用命令合集 命令选项和参数 Linux中的命令格式为:command [options] [arguments] //中括号表示可选的,即有些命令不需要选项也不需要参数,但有的命令在运行时需要多个 ...
- 洛谷 P3905 道路重建 题解
P3905 道路重建 题目描述 从前,在一个王国中,在\(n\)个城市间有\(m\)条道路连接,而且任意两个城市之间至多有一条道路直接相连.在经过一次严重的战争之后,有\(d\)条道路被破坏了.国王想 ...
- 算法:贪心、回溯(su)、分治、动态规划,思想简要
贪心算法: 只做出当前看来最好的选择,而不从整体考虑最优,他所作出的是局部最优解.使用该算法的前提是必须具备无后效性,即某个状态以前的选择不会影响以后的状态的选择,只与当前状态有关. 回溯算法: 本质 ...
- mysql distinct()函数 去重
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | t ...
- Linux进阶之Shell编程
1.什么是Shell Shell是一个命名行解释器,它为用户提供一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动.挂起.停止甚至是编写一些程序. 2.Shell脚本 ...
- 堆(heap)和栈(stack)有什么区别??
简单的可以理解为: heap:是由malloc之类函数分配的空间所在地.地址是由低向高增长的. stack:是自动分配变量,以及函数调用的时候所使用的一些空间.地址是由高向低减少的. 预备知识—程序的 ...
- CTF SSRF(服务器端伪造请求)
目录 CTF SSRF(服务器端伪造请求) 一.概念 二.危害 三.漏洞挖掘与判断 四.相关函数 五.IP绕过 六.Gopher协议 1.使用限制 2.构造payload CTF SSRF(服务器端伪 ...
- Plupload的几个demo
Plupload有以下功能和特点: 1.拥有多种上传方式:HTML5.flash.silverlight以及传统的<input type=”file” />.Plupload会自动侦测当前 ...