DEV Community

Discussion on: Car Price Prediction in Python

Collapse
 
anderrv profile image
Ander Rodriguez

Hi @dogers
Maybe something similar to ValueError: could not convert string to float: 'Diesel'?

Numeric values or dummies for Fuel are missing. You can group them like this:

cars['fuel'] = cars['fuel'].replace('Diesel', 0)
cars['fuel'] = cars['fuel'].replace('Gasoline', 1)
cars['fuel'] = cars['fuel'].replace(
    ['Electric/Gasoline', 'Electric/Diesel', 'Electric'],  2)
cars['fuel'] = cars['fuel'].replace(
    ['CNG', 'LPG', 'Others', '-/- (Fuel)', 'Ethanol', 'Hydrogen'], 3)
Enter fullscreen mode Exit fullscreen mode

or generate dummies

cars['fuel'] = cars['fuel'].replace('Others', 'OthersFuel')
fuelDummies = pd.get_dummies(cars.fuel)
cars = cars.join(fuelDummies)
cars = cars.drop('fuel', 1)
Enter fullscreen mode Exit fullscreen mode

Sorry for the inconvenience

Collapse
 
dogers profile image
Dogers

That's it! Used the dummies block and it's working again, thanks :)