Python pandas: output dataframe to csv with integers

后端 未结 6 689
囚心锁ツ
囚心锁ツ 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 03:09

    This is a "gotcha" in pandas (Support for integer NA), where integer columns with NaNs are converted to floats.

    This trade-off is made largely for memory and performance reasons, and also so that the resulting Series continues to be “numeric”. One possibility is to use dtype=object arrays instead.

提交回复
热议问题