Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

cannot convert float nan to integer

# x contained NaN
df = df[~df['x'].isnull()]

# Y contained some other garbage, so null check was not enough
df = df[df['y'].str.isnumeric()]

# final conversion now worked
df[['x']] = df[['x']].astype(int)
df[['y']] = df[['y']].astype(int)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #float #nan #integer
ADD COMMENT
Topic
Name
4+2 =