赞
踩
import pandas
from pandas import set_option
#括号里面直接指定了数据的来源,当然你也可以按照老师视频中所讲授的来操作
iris = pandas.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')
iris.columns=['sepal_length','sepal_width','petal_length','petal_width','species']
print (iris.head(10))
sepal_length sepal_width petal_length petal_width species 0 4.9 3.0 1.4 0.2 Iris-setosa 1 4.7 3.2 1.3 0.2 Iris-setosa 2 4.6 3.1 1.5 0.2 Iris-setosa 3 5.0 3.6 1.4 0.2 Iris-setosa 4 5.4 3.9 1.7 0.4 Iris-setosa 5 4.6 3.4 1.4 0.3 Iris-setosa 6 5.0 3.4 1.5 0.2 Iris-setosa 7 4.4 2.9 1.4 0.2 Iris-setosa 8 4.9 3.1 1.5 0.1 Iris-setosa 9 5.4 3.7 1.5 0.2 Iris-setosa
print(iris.shape)
(149, 5)
print(iris.dtypes)
sepal_length float64 sepal_width float64 petal_length float64 petal_width float64 species object dtype: object
set_option('display.width', 100)
# 设置数据的精确度
set_option('precision', 4)
print(iris.describe())
sepal_length sepal_width petal_length petal_width count 149.0000 149.0000 149.0000 149.0000 mean 5.8483 3.0510 3.7745 1.2054 std 0.8286 0.4335 1.7597 0.7613 min 4.3000 2.0000 1.0000 0.1000 25% 5.1000 2.8000 1.6000 0.3000 50% 5.8000 3.0000 4.4000 1.3000 75% 6.4000 3.3000 5.1000 1.8000 max 7.9000 4.4000 6.9000 2.5000
print(iris.groupby('species').size())
species Iris-setosa 49 Iris-versicolor 50 Iris-virginica 50 dtype: int64
set_option('display.width', 100)
# 设置数据的精确度
set_option('precision', 2)
print(iris.corr(method='pearson')) # 皮尔逊相关系数判断相关性:1 表示变量完全正相关, 0 表示无关,-1 表示完全负相关。
sepal_length sepal_width petal_length petal_width sepal_length 1.00 -0.10 0.87 0.82 sepal_width -0.10 1.00 -0.42 -0.35 petal_length 0.87 -0.42 1.00 0.96 petal_width 0.82 -0.35 0.96 1.00
print(iris.skew()) # skew()函数的结果,显示了数据分布的左偏或右偏。当数据接近0是,表示数据的偏差非常小。
sepal_length 0.30 sepal_width 0.35 petal_length -0.29 petal_width -0.12 dtype: float64
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。