python - Pandas appending .0 to a number -


i'm having issues pandas i'm little baffled on. have file lot of numeric values not need calculations. of them coming out fine, have couple getting ".0" appended end.

here sample input file:

id1         id2      age     id3 "sn19602","1013743", "24", "23523" "sn20077","2567897", "28", "24687" 

and output being generated:

id1         id2      age     id3 "sn19602","1013743.0", "24", "23523" "sn20077","2567897.0", "28", "24687" 

can explain why not of numeric values getting .0 appended, , if there way can prevent it? problem when perform next step of process csv output.

i have tried convert data frame , column string did not make impact. ideally not want list each column convert because have large number of columns , manually have go through output file figure out ones getting .0 appended , code it. suggestions appreciated.

import pandas pd import csv  df_inputfile = pd.read_csv("inputfile.csv") df_mappingfile = pd.read_csv("mappingfile.csv") df_merged = df_inputfile.merge(df_mappingfile, left_on="id", right_on="id", how="left") #this isn't affecting output df_merged.astype(str) df_merged.to_csv("output.csv", index=false, quoting=csv.quote_all) 

pandas.dataframe.to_csv has parameter float_format, takes regular float formatting string. should work:

df_merged.to_csv("output.csv", index=false, quoting=csv.quote_all, float_format='%.0f') 

Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -