# Python数据分析模块 | pandas做数据分析(三):统计相关函数

1、pandas.series.value_counts

Series.value_counts(normalize=False,sort=True,ascending=False, bins=None, dropna=True)

## 2.pandas.DataFrame.count

DataFrame.count(axis=0, level=None, numeric_only=False) Return Series with number of non-NA/null observations over requested axis. Works with non-floating point data as well (detects NaN and None)

Parameters: axis : {0 or ‘index’, 1 or ‘columns’}, default 0 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise level : int or level name, default None If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a DataFrame numeric_only : boolean, default False Include only float, int, boolean data Returns: count : Series (or DataFrame if level specified)

pandas.dataframe.sum

DataFrame.sum(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

```参数:
axis : {index (0), columns (1)}
skipna : 布尔值,默认为True.表示跳过NaN值.如果整行/列都是NaN,那么结果也就是NaN
level : int or level name, default None
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series
numeric_only : boolean, default None
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Returns:
sum : Series or DataFrame (if level specified)
import numpy as np
import pandas as pd
df=pd.DataFrame(data=[[1.4,np.nan],[7.1,-4.5],[np.nan,np.nan],[0.75,-1.3]],                index=["a","b","c","d"],
columns=["one","two"])
print("df:")
print(df)
#直接使用sum()方法,返回一个列求和的Series,自动跳过NaN值
print("df.sum()")
print(df.sum())
#当轴为1.就会按行求和
print("df.sum(axis=1)")
print(df.sum(axis=1))
#选择skipna=False可以禁用跳过Nan值
print("df.sum(axis=1,skipna=False):")
print(df.sum(axis=1,skipna=False))```

2、pandas.dataframe.mean

DataFrame.mean(axis=None,skipna=None,level=None,numeric_only=None, **kwargs)

```import numpy as np
import pandas as pd
df=pd.DataFrame(data=[[1.4,np.nan],[7.1,-4.5],[np.nan,np.nan],[0.75,-1.3]],
index=["a","b","c","d"],
columns=["one","two"])
print("df:")
print(df)
#直接使用mean()方法,返回一个列求平均数的Series,自动跳过NaN值
print("df.mean()")
print(df.mean())
#当轴为1.就会按行求平均数
print("df.mean(axis=1)")
print(df.mean(axis=1))
#选择skipna=False可以禁用跳过Nan值
print("df.mean(axis=1,skipna=False):")
print(df.mean(axis=1,skipna=False))```

1、pandas.dataframe.sort_values

DataFrame.sort_values(by,axis=0,ascending=True,inplace=False, kind='quicksort', na_position='last')

Sort by the values along either axis

424 篇文章81 人订阅

0 条评论

## 相关文章

### PHP数据结构（八） ——赫夫曼树实现字符串编解码(实践1)

PHP数据结构（八）——赫夫曼树实现字符串编解码(实践1) （原创内容，转载请注明来源，谢谢） 公众号规定不能超过3000字，只能分两篇，见谅。 ...

34012

### Python数据科学手册（三）【Pandas的对象介绍】

Pandas构建在Numpy的基础上，它同时支持行和列的操作。 使用pip进行安装：

513

### 玩转Pandas，让数据处理更easy系列1

Series 是pandas两大数据结构中（DataFrame，Series）的一种，我们先从Series的定义说起，Series是一种类似于一维数组的对象，它...

1202

2009

1683

4539

673

5619

951

### Numpy&Pandas

Numpy & Pandas 简介 此篇笔记参考来源为《莫烦Python》 运算速度快：numpy 和 pandas 都是采用 C 语言编写, pandas 又...

3149