【发布时间】:2020-10-29 23:07:03
【问题描述】:
我有一个带有 str 值的 pandas 列。我需要将其类型更改为int。问题是所有值都用 (' ') 分隔以区分 Ks 和 Ms,例如:
a = '17 000 000'
int(a)
print(a)
输出:
17000000
【问题讨论】:
-
df['col'].str.replace(' ', '').astype(int)或pd.to_numeric(df['col'].str.replace(' ', '')) -
完美感谢工作顺利
标签: python pandas dataframe type-conversion numeric