Python pandas: output dataframe to csv with integers

后端 未结 6 695
囚心锁ツ
囚心锁ツ 2020-12-08 02:15

I have a pandas.DataFrame that I wish to export to a CSV file. However, pandas seems to write some of the values as float instead of int

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 02:53

    You can change your DataFrame into Numpy array as a workaround:

     np.savetxt(savepath, np.array(df).astype(np.int), fmt='%i', delimiter = ',', header= 'PassengerId,Survived', comments='')
    

提交回复
热议问题