Mar-04-2024, 05:53 AM
Hi, I am a newbie to Python.
Am trying to impute a categorical column with mode but failed. Not sure what is the problem :
data.loc[(data.horsepower.isna() == True), 'horsepower']
206 NaN
265 NaN
326 NaN
Name: horsepower, dtype: object
data.loc[(data.horsepower.isna() == True), 'horsepower'] = data.horsepower.mode()
The 3 missing columns rows are not replaced when I rerun the above check (still shows 3 rows with NaN).
But if I replace it wit a hardcode value, it works :
data.loc[(data.horsepower.isna() == True), 'horsepower'] = '9999'
206 9999
265 9999
326 9999
Name: horsepower, dtype: object
Any advice is appreciated. Thank you!
Am trying to impute a categorical column with mode but failed. Not sure what is the problem :
data.loc[(data.horsepower.isna() == True), 'horsepower']
206 NaN
265 NaN
326 NaN
Name: horsepower, dtype: object
data.loc[(data.horsepower.isna() == True), 'horsepower'] = data.horsepower.mode()
The 3 missing columns rows are not replaced when I rerun the above check (still shows 3 rows with NaN).
But if I replace it wit a hardcode value, it works :
data.loc[(data.horsepower.isna() == True), 'horsepower'] = '9999'
206 9999
265 9999
326 9999
Name: horsepower, dtype: object
Any advice is appreciated. Thank you!