MulaiMulai sekarang secara gratis

One-hot encoding specific columns

A local used car dealership wants your help in predicting the sale price of their vehicles. If you use one-hot encoding on the entire used_cars dataset, the new dataset has over 1,200 columns. You are worried that this might lead to problems when training your machine learning models to predict price. You have decided to try a simpler approach and only use one-hot encoding on a few columns.

Latihan ini adalah bagian dari kursus

Working with Categorical Data in Python

Lihat Kursus

Petunjuk latihan

  • Create a new dataset, used_cars_simple, with one-hot encoding for these columns: "manufacturer_name" and "transmission" (in this order).
  • Set the prefix of all new columns to "dummy", so that you can easily filter to newly created columns.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create one-hot encoding for just two columns
used_cars_simple = pd.____(
  used_cars,
  # Specify the columns from the instructions
  ____,
  # Set the prefix
  ____
)

# Print the shape of the new dataset
print(used_cars_simple.shape)
Edit dan Jalankan Kode