MulaiMulai sekarang secara gratis

Matching on unique combinations

Joining on a single column like type can produce too many matches when that column isn't unique. A type_benchmarks DataFrame has target prices for specific type and beach combinations. To get one benchmark per listing, join on both columns so each combination uniquely identifies a row.

polars is loaded as pl, and the DataFrames hotels and type_benchmarks are available for you.

Latihan ini adalah bagian dari kursus

Data Transformation with Polars

Lihat Kursus

Petunjuk latihan

  • Join hotels with type_benchmarks on type and beach, keeping only rows that match in both DataFrames.
  • Print a few rows to verify the result.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Join on type and beach for unique matches
with_targets = hotels.____(type_benchmarks, on=["____", "____"], how="____")

# Print a few rows
print(with_targets.____())
Edit dan Jalankan Kode