Java教程

06-Panda统计计算和描述

本文主要是介绍06-Panda统计计算和描述,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import numpy as np
import pandas as pd
df=pd.DataFrame([[1.4,np.nan],[7.1,-4.5],
                [np.nan,np.nan],[0.75,-1.3]],
                index=['a','b','c','d'],
                columns=['one','two'])
df
onetwo
a1.40NaN
b7.10-4.5
cNaNNaN
d0.75-1.3
#默认按列求和
df.sum()
one    9.25
two   -5.80
dtype: float64
# 按行求和
df.sum(axis=1)   # skipna = False
a    1.40
b    2.60
c    0.00
d   -0.55
dtype: float64
df.idxmax()
one    b
two    d
dtype: object
df.cumsum()
onetwo
a1.40NaN
b8.50-4.5
cNaNNaN
d9.25-5.8
# 汇总统计
df.describe()
onetwo
count3.0000002.000000
mean3.083333-2.900000
std3.4936852.262742
min0.750000-4.500000
25%1.075000-3.700000
50%1.400000-2.900000
75%4.250000-2.100000
max7.100000-1.300000
s1 = pd.Series(['a','a','b','c']*4)
s1
0     a
1     a
2     b
3     c
4     a
5     a
6     b
7     c
8     a
9     a
10    b
11    c
12    a
13    a
14    b
15    c
dtype: object
s1.describe()
count     16
unique     3
top        a
freq       8
dtype: object

                    
这篇关于06-Panda统计计算和描述的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!