Home > OS >  python output incomplete and trailing .0
python output incomplete and trailing .0

Time:03-05

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

CodePudding user response:

While reading the csv file mention the parameter dtype as below code

result_1=pd.read_csv('H:\\1\\1.csv',encoding="utf-8",dtype=str)
  • Related