【发布时间】:2019-12-01 08:42:51
【问题描述】:
我正在尝试将 Series 对象转换为整数。但我很难做到这一点。每次我尝试某些东西时,我都会遇到一个新错误。
- 我尝试使用
pd.to_numeric进行转换,解析字符串None时出错 - 然后我尝试用
NaN替换None值:替换问题
#1.1)
pd.to_numeric(df['Var1'], downcast = 'integer')
ValueError: Unable to parse string "None" at position 44816
#1.2)
df.astype({'Var1':'int64'}).dtypes
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
#2)
df['Var1'].astype(str).astype(int)
ValueError: invalid literal for int() with base 10: 'None'
实际结果:dtype:object
预期结果:dtype:int64
【问题讨论】:
标签: python string pandas int jupyter