两个Excel表格,名称分别为“报表”、“NC”均为1张sheet,数据均在第1张sheet中第一列,已利用pandas读取数据,想利用第一列创建列表,且第一行第一列名称已经改为name,系统依然报错,请问大家需要如何解决。或者需要如何调整代码,才能将第一列成功构建列表
pandas读取execl后的数据如何引用第一列为列表
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- 游一游走一走 2022-10-11 20:42关注
删除index_col参数即可,你对这个参数理解有误
useclos参数表示你需要读取哪些列,index_col表示用这作为行索引,所以name列当索引列了import pandas as pd import difflib origin_data=pd.read_excel("NC.xlsx") target_data=pd.read_excel("report.xlsx") pool_item=origin_data['name'] search_item=target_data['name'] print(len(pool_item),len(search_item)) def get_closest(str,sequences): result=difflib.get_close_matches(str,sequences,n=1,cutoff=0.3) result=result if result else [] ratio=difflib.SequenceMatcher(None,str,result).ratio() return result,ratio search_keys=[] target=[] ratios=[] for item in search_item: result,ratio = get_closest(item,pool_item) if (len(result)==0): continue search_keys.append(item) target.append(result) ratios.append(ratio) match={"tr12":search_keys,"NC":target,"t3":ratios} match=pd.DataFrame(match) print(match) match.to_excel("test.xlsx")
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan