熊猫将big int转换为字符串以避免科学计数法

时间:2020-04-11 08:55:33

标签: python pandas

我有一个来自csv文件的数据帧,该数据帧使用pandas.read_csv()方法加载,如下所示:

                   id  col
0 1151377158377549824 row0
1 1151346166619103232 row1
2 1151737502769827840 row2

列的类型是:

df.dtypes
out:
id        float64
col       object

我想将id的类型更改为字符串,但使用astype(str)或apply(str),将其转换为科学计数法后:

                      id  col
0 1.1513771583775498e+18 row0
1 1.1513461666191032e+18 row1
2 1.1517375027698278e+18 row2

如何避免转换后的科学计数法?

1 个答案:

答案 0 :(得分:1)

您可以先转换为Int64,然后转换为字符串:

df['id'] = df['id'].astype("Int64").astype(str)
df

输出:

enter image description here

相关问题