Answers for "pandas convert column float to int with nan"

3

pandas convert float to int

df['col'] = df['col'].astype(int)
Posted by: Guest on January-25-2021
4

python pandas convert nan to 0

pandas.DataFrame.fillna(0)
Posted by: Guest on May-22-2020
0

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)
Posted by: Guest on October-06-2021

Code answers related to "pandas convert column float to int with nan"

Python Answers by Framework

Browse Popular Code Answers by Language