pandas将string Series转换为int Series

时间:2017-02-15 18:05:51

标签: python pandas

我在将整数和空值的字符串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

0 个答案:

没有答案