关注微信号:小程在线
关注CSDN博客:程志伟的博客
Python描述性统计、偏度与峰度、均匀分布、正态分布、二项分布、几何分布、泊松分布、指数分布
Type "copyright", "credits" or "license" for more information.
IPython 7.6.1 -- An enhanced Interactive Python.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
#导入新的数据
mtcars=pd.read_csv('H:/0date/mtcars.csv')
mtcars.head()
Out[2]:
name mpg cyl disp hp ... qsec vs am gear carb
0 Mazda RX4 21.0 6 160.0 110 ... 16.46 0 1 4 4
1 Mazda RX4 Wag 21.0 6 160.0 110 ... 17.02 0 1 4 4
2 Datsun 710 22.8 4 108.0 93 ... 18.61 1 1 4 1
3 Hornet 4 Drive 21.4 6 258.0 110 ... 19.44 1 0 3 1
4 Hornet Sportabout 18.7 8 360.0 175 ... 17.02 0 0 3 2
[5 rows x 12 columns]
#将name列作为索引列
mtcars.set_index(['name'],inplace=True)
mtcars.head()
Out[3]:
mpg cyl disp hp drat ... qsec vs am gear carb
name ...
Mazda RX4 21.0 6 160.0 110 3.90 ... 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 ... 17.02 0 1 4 4
Datsun 710 22.8 4 108.0 93 3.85 ... 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 ... 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360.0 175 3.15 ... 17.02 0 0 3 2
[5 rows x 11 columns]
#查看每列的均值
mtcars.mean()
Out[4]:
mpg 20.090625
cyl 6.187500
disp 230.721875
hp 146.687500
drat 3.596563
wt 3.217250
qsec 17.848750
vs 0.437500
am 0.406250
gear 3.687500
carb 2.812500
dtype: float64
#每列的中位数
mtcars.median()
Out[5]:
mpg 19.200
cyl 6.000
disp 196.300
hp 123.000
drat 3.695
wt 3.325
qsec 17.710
vs 0.000
am 0.000
gear 4.000
carb 2.000
dtype: float64
#查看每行的均值
mtcars.mean(axis=1)
Out[6]:
name
Mazda RX4 29.907273
Mazda RX4 Wag 29.981364
Datsun 710 23.598182
Hornet 4 Drive 38.739545
Hornet Sportabout 53.664545
Valiant 35.049091
Duster 360 59.720000
Merc 240D 24.634545
Merc 230 27.233636
Merc 280 31.860000
Merc 280C 31.787273
Merc 450SE 46.430909
Merc 450SL 46.500000
Merc 450SLC 46.350000
Cadillac Fleetwood 66.232727
Lincoln Continental 66.058545
Chrysler Imperial 65.972273
Fiat 128 19.440909
Honda Civic 17.742273
Toyota Corolla 18.814091
Toyota Corona 24.888636
Dodge Challenger 47.240909
AMC Javelin 46.007727
Camaro Z28 58.752727
Pontiac Firebird 57.379545
Fiat X1-9 18.92