I'm having trouble converting a string Series
of integers and nulls to an integer Series
. Coming from an R background, I'm not sure why this doesn't convert to int
when I call 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)
returns:
ValueError: cannot convert float NaN to integer