Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mode()
#1
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!
Reply


Messages In This Thread
mode() - by huey17 - Mar-04-2024, 05:53 AM
RE: mode() - by deanhystad - Mar-05-2024, 05:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  things that work in terminal mode but not in sublime mode alok 4 2,933 Aug-11-2021, 07:02 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020