我在将整数和空值的字符串Series
转换为整数Series
时遇到问题。来自R背景,我不确定为什么当我致电int
时,这不会转换为out.astype(int)
:
series = pd.Series([
'Employee: Trump, Donald ID: 81780 Time Zone: Pacific', 'some text',
'Employee: Obama, Barack ID: 84428 Time Zone: Pacific', 'some text'
])
out = series.str.split(
' ID: '
).str.get(1).str.split(
' Time Zone: '
).str.get(0)
out.astype(int)
返回:
ValueError: cannot convert float NaN to integer