p['WinRx Per Person']
0 -1,100.00
1 -1,100.00
2 -1,850.00
3 -200
4 -925
5 -925
6 -1,100.00
7 -1,850.00
8 -925
9 -925
10 -1,850.00
11 -1,850.00
12 -1,100.00
13 -1,850.00
14 -1,100.00
type('WinRx Per Person')
str
p['WinRx Per Person'].astype(int)
invalid literal for int() with base 10: '-1,100.00'
当我尝试将字符串类型转换为int以便使用abs()函数时,会抛出错误
答案 0 :(得分:1)
在to_numeric
之后使用replace
pd.to_numeric(df['WinRx Per Person'].str.replace(',',''))
Out[248]:
0 -1100.0
1 -1100.0
2 -1850.0
3 -200.0
4 -925.0
5 -925.0
6 -1100.0
7 -1850.0
8 -925.0
9 -925.0
10 -1850.0
11 -1850.0
12 -1100.0
13 -1850.0
14 -1100.0
Name: WinRx Per Person, dtype: float64