sklearn-查看数据(第2讲)
发布日期:2021-06-29 14:44:30
浏览次数:3
分类:技术文章
本文共 5794 字,大约阅读时间需要 19 分钟。
查看数据 2020/5/27=====================================================================================1.1.查看数据维度,类型属性;1.2.简单的数据统计分析;数据的相关系及分布;=====================================================================================2.实例:#说明:在pycharm中数据不美观;在spyder中打印显示对的相当齐import csv,pandas as pd,numpy as nppd.set_option('display.width', 100)pd.set_option('precision', 4) # 设置数据的精确度pd.set_option('display.max_columns', 1000)pd.set_option('display.unicode.ambiguous_as_wide', True)#pd.DataFrame打印显示对齐pd.set_option('display.unicode.east_asian_width', True)#这两个函数为print对齐;在pycharm中仍不美观def fillEmptyStr(str0,width=12,precision=4): n,n_pos=len(str0),str0.find('.') if n_pos<0: if n>=width: result=str0[0:width] else: result=str0+' '*(width-n) else: if n_pos+1+precision<=n: result=str0[0:(n_pos+1+precision)] else: result=str0+' '*(n-n_pos-1-precision) return resultdef print_df(df,width=12,precision=4): if isinstance(df,pd.DataFrame): str_i='{:<'+str(width)+'}' rows,cols=df.index,df.columns data=df.to_numpy() n=0 r,c=data.shape print(str_i.format(' '*width),end='') for col in cols: tmp=fillEmptyStr(str(col),width,precision) print(str_i.format(tmp),end='') print() for i in range(r): tmp=fillEmptyStr(str(rows[n]),width,precision) print(str_i.format(tmp),end='') n=n+1 for j in range(c): tmp=fillEmptyStr(str(data[i,j]),width,precision) print(str_i.format(tmp),end='') print() else: print(df)=====================================================================================# 显示数据的行和列数据filename = 'pima_data.csv'names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']data = pd.read_csv(filename, names=names)print('data.dtypes=')print(data.dtypes)# 显示数据的行和列数据print('data.shape=',data.shape)# 显示数据的行和列数据print('data.class=')print_df(data.groupby('class').size())# 数据分类分布统计print('data.skew=')print_df(data.skew())# 计算数据的高斯偏离print('data.corr=')print_df(data.corr(method='pearson'))# 显示数据的相关性print('data.describe=')print_df(data.describe())# 描述性统计print('data.head(4)=')print_df(data.head(4))# 显示数据最初4行====================================================================================="""data.dtypes=preg int64plas int64pres int64skin int64test int64mass float64pedi float64age int64class int64dtype: objectdata.shape= (768, 9)data.class=class0 5001 268dtype: int64data.skew=preg 0.9017plas 0.1738pres -1.8436skin 0.1094test 2.2723mass -0.4290pedi 1.9199age 1.1296class 0.6350dtype: float64data.corr= preg plas pres skin test mass pedi age class preg 1.0 0.1294 0.1412 -0.0816 -0.0735 0.0176 -0.0335 0.5443 0.2218 plas 0.1294 1.0 0.1525 0.0573 0.3313 0.2210 0.1373 0.2635 0.4665 pres 0.1412 0.1525 1.0 0.2073 0.0889 0.2818 0.0412 0.2395 0.0650 skin -0.0816 0.0573 0.2073 1.0 0.4367 0.3925 0.1839 -0.1139 0.0747 test -0.0735 0.3313 0.0889 0.4367 1.0 0.1978 0.1850 -0.0421 0.1305 mass 0.0176 0.2210 0.2818 0.3925 0.1978 1.0 0.1406 0.0362 0.2926 pedi -0.0335 0.1373 0.0412 0.1839 0.1850 0.1406 1.0 0.0335 0.1738 age 0.5443 0.2635 0.2395 -0.1139 -0.0421 0.0362 0.0335 1.0 0.2383 class 0.2218 0.4665 0.0650 0.0747 0.1305 0.2926 0.1738 0.2383 1.0 data.describe= preg plas pres skin test mass pedi age class count 768.0 768.0 768.0 768.0 768.0 768.0 768.0 768.0 768.0 mean 3.8450 120.8945 69.1054 20.5364 79.7994 31.9925 0.4718 33.2408 0.3489 std 3.3695 31.9726 19.3558 15.9522 115.2440 7.8841 0.3313 11.7602 0.4769 min 0.0 0.0 0.0 0.0 0.0 0.0 0.078 21.0 0.0 25% 1.0 99.0 62.0 0.0 0.0 27.3 0.2437 24.0 0.0 50% 3.0 117.0 72.0 23.0 30.5 32.0 0.3725 29.0 0.0 75% 6.0 140.25 80.0 32.0 127.25 36.6 0.6262 41.0 1.0 max 17.0 199.0 122.0 99.0 846.0 67.1 2.42 81.0 1.0 data.head(4)= preg plas pres skin test mass pedi age class 0 6.0 148.0 72.0 35.0 0.0 33.6 0.627 50.0 1.0 1 1.0 85.0 66.0 29.0 0.0 26.6 0.3510 31.0 0.0 2 8.0 183.0 64.0 0.0 0.0 23.3 0.672 32.0 1.0 3 1.0 89.0 66.0 23.0 94.0 28.1 0.1669 21.0 0.0 """======================================================================================
转载地址:https://chunyou.blog.csdn.net/article/details/106388965 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月27日 18时47分01秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
聊聊我是如何编程入门的
2019-04-29
J-Link该如何升级固件?
2019-04-29
485通信自动收发电路,历史上最详细的解释
2019-04-29
一位头发发白的神人教你怎么写程序,运维,买电脑,写文章,平面设计!
2019-04-29
「第三篇」全国电子设计竞赛,这些你必须知道的比赛细节,文末附上近十年电赛题目下载...
2019-04-29
5G小科普(漫画版,So easy!)
2019-04-29
「第四篇」电赛控制题可以准备一些什么?
2019-04-29
「第六篇」对于电赛,我们应该看重什么?
2019-04-29
树莓派翻车了
2019-04-29
这位电子工程师,你不能错过。
2019-04-29
「重磅猜题之第二篇」2019年大学生电子设计竞赛
2019-04-29
干货分享 JVM 之第 3 篇 —— Java 内存结构相关
2019-04-29
基于 Hystrix 高并发服务限流第 2 篇 —— 服务隔离(线程池隔离、信号量隔离)
2019-04-29
SpringBoot 整合 JWT 实现统一认证
2019-04-29
TypeError: this.getOptions is not a function
2019-04-29
el-table 二维数组合并行
2019-04-29
UR5e机械臂运行一直阻塞在waitForServer
2019-04-29
ROS把pkg1下的某个头文件和源文件生成动态链接库供pkg2调用
2019-04-29
使用urdf_tutorial快速可视化urdf文件
2019-04-29