【发布时间】:2021-12-20 17:18:06
【问题描述】:
尽管同一个问题已被多次询问。我似乎没有让它工作。 我使用 python 3.8 并读取这样的 excel 文件
df = pd.read_excel(r"filename.xlsx")
A 列是 float64 类型,当我使用 spyder 打开 df 时,我看到这样的情况:"1.5934e+06"
所以,我需要把它变成一个 7 位数的字符串,然后我使用了:
df["columnA] = df["columnA].astype(str).str.zfill(7)
但结果是:"1593396.0"
我怎样才能得到 this = 1593396 ?
我尝试将 '.0' 替换为 '',但没有成功。它没有从末尾获取“.0”,而是删除了单元格中的任何零!
【问题讨论】:
-
试试
df["columnA] = df["columnA].astype(int).astype(str).str.zfill(7)
标签: python-3.x pandas dataframe type-conversion float64