LoslegenKostenlos loslegen

Replacing multiple patterns

The analytics team needs to calculate average product sizes, but the size column contains text values like "30ml" instead of numbers. You can replace multiple patterns at once to clean these values.

Diese Übung ist Teil des Kurses

Data Transformation with Polars

Kurs anzeigen

Anleitung zur Übung

  • Replace "30ml", "50ml", and "100ml" in the "size" column with their numeric equivalents "30", "50", and "100".
  • Cast the "size" column to a 64-bit integer.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Replace size values with numeric strings
reviews.with_columns(
    pl.col("size").str.____(["30ml","50ml","100ml"],["____","____","____"])
  
# Cast size column to integer
).____({"____":pl.Int64})
Code bearbeiten und ausführen