python输出不完整且尾随.0
我尝试对 csv 文件进行分类,但输出值尾随 .0
import pandas as pd
result_1=pd.read_csv('H:\\1\\1.csv',encoding="utf-8",)
SubNetwork_list=list(result_1.groupby(["Phone"]))
for SubNetwork in SubNetwork_list:
SubNetwork_pd=pd.DataFrame(SubNetwork[1])
SubNetwork_pd.to_csv("H:\\2\\"+str(SubNetwork[0])+".csv",mode='a', header=False,
index=False, encoding="utf-8")
我的 csv 文件
ID,name,addr1,addr2,state,ZipCode,Phone
661111154,DAVID,224 Collins Taft Rd,,RI,02830,8142154252
输出信息是
ID,name,addr1,addr2,state,ZipCode,Phone
661111154,DAVID,224 Collins Taft Rd,,RI,2830,8142154252.0
电话值尾随“.0”,邮政编码中缺少 0, 8142154252 → 8142154252.0, 02830 → 2830
如何让数字正确显示
I try to classify a csv file, but the output value gets trailing .0
import pandas as pd
result_1=pd.read_csv('H:\\1\\1.csv',encoding="utf-8",)
SubNetwork_list=list(result_1.groupby(["Phone"]))
for SubNetwork in SubNetwork_list:
SubNetwork_pd=pd.DataFrame(SubNetwork[1])
SubNetwork_pd.to_csv("H:\\2\\"+str(SubNetwork[0])+".csv",mode='a', header=False,
index=False, encoding="utf-8")
my csv file
ID,name,addr1,addr2,state,ZipCode,Phone
661111154,DAVID,224 Collins Taft Rd,,RI,02830,8142154252
The output information is
ID,name,addr1,addr2,state,ZipCode,Phone
661111154,DAVID,224 Collins Taft Rd,,RI,2830,8142154252.0
Phone values trailing ".0", 0 in Zipcode is missing,
8142154252 → 8142154252.0,
02830 → 2830
How to make numbers display properly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在读取 csv 文件时提及参数 dtype ,如下代码所示
While reading the csv file mention the parameter
dtype
as below code