I'm trying to convert multiple columns in my df from string to int and float. I used fillna method to get rid of NaN values however I'm still getting an error. Here's what I did:
df = [['column1', 'column2', 'column3', 'column4']]
df = df[['column1', 'column2', 'column3', 'column4']].fillna(0)
convert_dict = {'column1': int,
'column2': float,
'column3': int,
'column4': float}
df = df.astype(convert_dict)
The error says ValueError: cannot convert float NaN to integer
Edit: Removed inplace=True
df = [[...]].fillna(0, inplace=True)doesn't make sense. I'm assuming you are missing adfin there and you don't needinplaceif you are assigning the result todf.df = df[['column1'...instead ofdf = [['column1'...?df = df.astype(convert_dict, errors = 'ignore')should work.