1

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
mef jons
  • 232
  • 1
  • 3
  • 10
  • There is no missing value correspondence to integer type. `NaN` can only be float. – Psidom Feb 15 '17 at 18:08
  • Ah ok. Sorry for duplicate question. Is there a best practice around this? Should I just use float for any 'numeric' data? In R, I use numeric / float for both integer and float, because there aren't any drawbacks for most practical purposes. – mef jons Feb 15 '17 at 18:16
  • If most of the users are not complaining too much about the case, I guess it is the same situation here. Not sure if it is the best practice though. – Psidom Feb 15 '17 at 18:24

0 Answers0