pandas to_csv: suppress scientific notation in csv file when writing pandas to csv

后端 未结 3 551
我在风中等你
我在风中等你 2021-02-06 01:34

I am writing a pandas df to a csv. When I write it to a csv file, some of the elements in one of the columns are being incorrectly converted to scientific notation/numbers. Fo

3条回答
  •  日久生厌
    2021-02-06 02:14

    If you would like to use the values as formated string in a list, say as part of csvfile csv.writier, the numbers can be formated before creating a list:

    with open('results_actout_file','w',newline='') as csvfile:
         resultwriter = csv.writer(csvfile, delimiter=',')
         resultwriter.writerow(header_row_list)
    
         resultwriter.writerow(df['label'].apply(lambda x: '%.17f' % x).values.tolist())
    

提交回复
热议问题