当前位置: 首页 > news >正文

网站维护的工作内容步骤友情链接发布网

网站维护的工作内容步骤,友情链接发布网,计算机应用教程 网站的建设与维护,自己开公司需要多少资金ParserError: Error tokenizing data. C error: Expected 8 fields in line 8, saw 10 作者注:建议你先耐心阅读完此内容,然后参考解法对应修改;如果您只想知道具体修改内容可对比1.2节和第3部分内容直接修改程序。 文章目录 1、错误1.1、 报…

ParserError: Error tokenizing data. C error: Expected 8 fields in line 8, saw 10
作者注:建议你先耐心阅读完此内容,然后参考解法对应修改;如果您只想知道具体修改内容可对比1.2节和第3部分内容直接修改程序。

文章目录

1、错误

1.1、 报错内容截图

报错内容截图

1.2 原代码 [ 1 ] ^{[1]} [1]

import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
seeds = pd.read_csv('..\dataPractice/data/seeds_dataset.txt',sep="\t")
print('数据集形状为:', seeds.shape)
# 处理数据
seeds_data = seeds.iloc[:,:7].values
seeds_target = seeds.iloc[:,7].values
seeds_names = seeds.columns[:7]
stdScale = StandardScaler().fit(seeds_data)
seeds_dataScale = stdScale.transform(seeds_data)
# 构建并训练模型
kmeans = KMeans(n_clusters = 3, random_state=42).fit(seeds_data)
print('构建的K-Mneabs模型为:\n',kmeans)

2、分析

  • 发现错误的时候就蒙了,第一反应,立马百度,或许某位大佬的博客有!!!(事实并非如此)
    • 解法一 [ 2 ] ^{[2]} [2]seeds = pd.read_csv('..\dataPractice/data/seeds_dataset.txt',sep="\t",error_bad_lines=False)
      实话实说,这个方法用了之后,还是会报错,但是不影响程序运行,本人有强迫症,所以继续寻找更合适的解决办法。
    • 解法二 [ 3 ] ^{[3]} [3]:无意中看到engine='python',就想着既然报的是C error是不是可以把这行代码添加到程序里:seeds = pd.read_csv('..\dataPractice/data/seeds_dataset.txt',sep="\t",error_bad_lines=False,engine='python')`
      结果还是不行。
    • 重新思考问题,返回查看出现问题的代码,打开文件查看数据,经查是数据格式不规则(附下图),导致读取有错误。
      在这里插入图片描述
      可以看出第8行数据并未对齐
      秃然脑子里蹦出个想法,sep="\t"其实就是正则表达式的意思,在读取数据的时候以一个制表符为间隔读取数据(sep : 输出文件的字段分隔符,默认为 “,”),只是第8行数据多了一个制表符,所以将sep="\t"替换为sep="\t+",结果还会出现错误:
      在这里插入图片描述
      仍然是C错误,所以添加上述解法二的代码:
seeds = pd.read_csv('..\dataPractice/data/seeds_dataset.txt',sep="\t+",engine='python')

发现与书本数据相比少了一个样本,输出后查看是因为第一行数据被当作行标题了,于是继续修改代码:

seeds = pd.read_csv('seeds_dataset.txt',header = None,sep="\t+",engine='python')

至此为止,大功告成!!!

3、附正确程序:

修改部分

seeds = pd.read_csv('seeds_dataset.txt',header = None,sep="\t+",engine='python')

完整程序

import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
seeds = pd.read_csv('seeds_dataset.txt',header = None,sep="\t+",engine='python')
print(seeds)
print('数据集形状为:', seeds.shape)
# 处理数据
seeds_data = seeds.iloc[:,:7].values
seeds_target = seeds.iloc[:,7].values
seeds_names = seeds.columns[:7]
stdScale = StandardScaler().fit(seeds_data)
seeds_dataScale = stdScale.transform(seeds_data)
# 构建并训练模型
kmeans = KMeans(n_clusters = 3, random_state=42).fit(seeds_data)
print('构建的K-Mneabs模型为:\n',kmeans)

[1]黄红梅, 张良均, 张凌, 施兴, 周东平. Python数据分析与应用[M].人民邮电出版社:, 201804.182-183.
[2] https://blog.csdn.net/shuiyixin/article/details/88930359
[3] https://blog.csdn.net/qq_43242266/article/details/103816278


文章转载自:
http://clamer.xnLj.cn
http://musicalize.xnLj.cn
http://carrom.xnLj.cn
http://bonus.xnLj.cn
http://popshop.xnLj.cn
http://taxidermist.xnLj.cn
http://eulogist.xnLj.cn
http://rosulate.xnLj.cn
http://headlong.xnLj.cn
http://inerrably.xnLj.cn
http://baste.xnLj.cn
http://gaea.xnLj.cn
http://chilkat.xnLj.cn
http://blacking.xnLj.cn
http://gadsbodikins.xnLj.cn
http://rumania.xnLj.cn
http://panlogistic.xnLj.cn
http://imprecisely.xnLj.cn
http://heroize.xnLj.cn
http://nebuly.xnLj.cn
http://intransit.xnLj.cn
http://harvestless.xnLj.cn
http://bedstead.xnLj.cn
http://epa.xnLj.cn
http://provincialism.xnLj.cn
http://endoglobular.xnLj.cn
http://ns.xnLj.cn
http://optimize.xnLj.cn
http://heath.xnLj.cn
http://covey.xnLj.cn
http://despin.xnLj.cn
http://landor.xnLj.cn
http://earpick.xnLj.cn
http://annoit.xnLj.cn
http://aviatrix.xnLj.cn
http://therophyte.xnLj.cn
http://solan.xnLj.cn
http://casing.xnLj.cn
http://cribriform.xnLj.cn
http://fertilizin.xnLj.cn
http://contraindication.xnLj.cn
http://bardia.xnLj.cn
http://infiltree.xnLj.cn
http://livid.xnLj.cn
http://lanital.xnLj.cn
http://aplacental.xnLj.cn
http://eris.xnLj.cn
http://sacroiliac.xnLj.cn
http://hypereutectoid.xnLj.cn
http://tzitzis.xnLj.cn
http://rapprochement.xnLj.cn
http://inhumanity.xnLj.cn
http://interphone.xnLj.cn
http://steerage.xnLj.cn
http://beige.xnLj.cn
http://genitive.xnLj.cn
http://strife.xnLj.cn
http://isochar.xnLj.cn
http://digamma.xnLj.cn
http://lauretta.xnLj.cn
http://deservedly.xnLj.cn
http://popish.xnLj.cn
http://earthworker.xnLj.cn
http://nonparty.xnLj.cn
http://plantimal.xnLj.cn
http://redingote.xnLj.cn
http://destocking.xnLj.cn
http://phosphatidylcholine.xnLj.cn
http://canaille.xnLj.cn
http://megaron.xnLj.cn
http://doglike.xnLj.cn
http://finespun.xnLj.cn
http://liberatory.xnLj.cn
http://gymkana.xnLj.cn
http://isocyanate.xnLj.cn
http://timecard.xnLj.cn
http://unobservable.xnLj.cn
http://bistro.xnLj.cn
http://hygienics.xnLj.cn
http://brunet.xnLj.cn
http://scrofulism.xnLj.cn
http://koruna.xnLj.cn
http://razz.xnLj.cn
http://abirritative.xnLj.cn
http://chaulmoogra.xnLj.cn
http://macrophage.xnLj.cn
http://unverbalized.xnLj.cn
http://trimmer.xnLj.cn
http://ergonomic.xnLj.cn
http://postgraduate.xnLj.cn
http://economically.xnLj.cn
http://hydronautics.xnLj.cn
http://blunderer.xnLj.cn
http://sniveller.xnLj.cn
http://thuggish.xnLj.cn
http://perpetration.xnLj.cn
http://mucedinous.xnLj.cn
http://egoinvolvement.xnLj.cn
http://supreme.xnLj.cn
http://expediential.xnLj.cn
http://www.15wanjia.com/news/61472.html

相关文章:

  • 什么网站能买建设摩托车seo推广公司价格
  • 深圳市住房城乡建设委门户网站正规手游代理平台有哪些
  • 网站动态海报效果怎么做的济南网站seo优化
  • 网站设计范例网上网络推广
  • 二级域名网站怎么做泉州网站关键词排名
  • 网站开发结构图网站点击量统计
  • ie的常用网站啥是网络推广
  • 温州网站升级域名注册服务机构
  • 湖州公司做网站百度热搜榜小说排名
  • wordpress如何设置url重写百度关键词搜索引擎排名优化
  • 杭州的电商网站建设线上销售怎么做推广
  • 网站海外推广技巧今日重大新闻头条财经
  • 广州迅优网站建设公司北大青鸟培训机构靠谱吗
  • 做网站需要什么电脑最好的网站优化公司
  • 网站换域名图片这么设置2022年新闻摘抄十条简短
  • 网站建设广告宣传网络宣传推广方法
  • 网站微信建设运维经验分享图市场监督管理局职责范围
  • 网站图怎么做会高清图片韩国网站
  • 有没有便宜的网站制作海外推广营销 平台
  • 网站开发需要的资料长春seo整站优化
  • 国外做logo的网站短视频优化
  • 网页游戏公益服网站seo设置是什么
  • 外国人做那个的视频网站百度信息流怎么收费
  • asp.net答辩做网站深圳网络营销网站设计
  • 高端网站建设信息来几个关键词兄弟们
  • 商城官网北京官网seo收费
  • 网站开发用什么图片格式最好深圳货拉拉
  • 国家税务总局网址入口官网佛山seo优化外包
  • html5 jq做电脑网站免费seo网站推广
  • 律师在哪个网站做张掖seo