BaşlayınÜcretsiz başlayın

Transforming text data

You notice product names in your grocery inventory database have inconsistent formats. Some have parentheses like "Apple (Organic)", extra spaces, and mixed capitalization. This makes it hard to match and analyze products accurately. Standardize these names by removing parenthetical descriptions, cleaning up surrounding spaces, and converting to lowercase.

Bu egzersiz, kursun bir parçasıdır

Cleaning Data in Java

Kursa Göz Atın

Egzersiz talimatları

  • Map product names through cleaning operations.
  • Remove parentheses from each name.
  • Remove surrounding space from each name.
  • Convert each name to lowercase.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

public class GroceryDataTransformation {
    public static void main(String[] args) {
        Table inventory = Table.read().csv("grocery_inventory.csv");

        StringColumn names = inventory.stringColumn("Product_Name");
        StringColumn standardizedNames =
            // Map product names through cleaning operations
            ____.____(
                // Remove parentheses
                t -> t.____("\\(.*\\)", "")
                      // Remove surrounding space
                      .____()
                      // Convert to lowercase
                      .____())
            .setName("Standardized_Names");

        System.out.println("Example name before cleaning: " + names.get(84));
        System.out.println("Example name after cleaning: " + standardizedNames.get(84));
    }
}
Kodu Düzenle ve Çalıştır