Python pandas: output dataframe to csv with integers

后端 未结 6 694
囚心锁ツ
囚心锁ツ 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 use astype() to specify data type for each column

    For example:

    import pandas
    df = pandas.DataFrame(data, columns=['a','b','c','d'], index=['x','y','z'])
    
    df = df.astype({"a": int, "b": complex, "c" : float, "d" : int})
    

提交回复
热议问题