Menu
CoddyTech

Recap: Car Listings

Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 55 of 64.

challenge icon

Challenge

Medium

A used car site preps listings for a price model. listings.csv has fuel, condition (fair, good, excellent), km and price. The program reads a fuel.

  1. Add condition_score: fair 1, good 2, excellent 3.
  2. Add mileage: low up to 50000 km, mid up to 120000, high up to 300000.
  3. One-hot encode fuel into cars (dtype=int).
  4. Print the shape, cars per mileage band, and the read fuel's count, mean price and mean condition (2 decimals).

Five other listings become this table:

Five other listings: the 4 columns fuel, condition, km and price become 8. condition, km and price stay; condition gives condition_score, km gives mileage, and fuel becomes fuel_diesel, fuel_hybrid and fuel_petrol

With the input hybrid, they print:

Shape: (5, 8)
mileage
low     1
mid     3
high    1
Name: count, dtype: int64
hybrid listings: 3
Mean price: 10500.0
Mean condition: 2.0

Try it yourself

import pandas as pd

cars = pd.read_csv("listings.csv")
fuel = input()

# Write your code below

All lessons in Statistics for ML

Practice on your own: Online Python compiler