Tablo filtreleme
Artık temel ürün kataloğunu yüklediğine göre, girişim şirketi ileri seviye eğitimleri için premium ürünlere odaklanmak istiyor. Hangi ürünlerin "premium" (fiyatı 800 $ üzeri) sayıldığını belirleyip pazarlama ekibi için filtrelenmiş bir veri kümesi oluşturman gerekiyor.
Table, DoubleColumn ve Selection sınıfları senin için içe aktarıldı.
Bu egzersiz, kursun bir parçasıdır
Java'da Veri İçe Aktarma
Egzersiz talimatları
"Price"sütunu için800'den büyük değerleri seçen birSelectionoluştur.- Ürünler tablosunu bu
Selectionile filtrele. - Premium ürünlerin satır sayısını yazdır.
- Premium ürünlerin ortalama fiyatını yazdır.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
public class ProductCatalog {
public static void main(String[] args) {
try {
Table products = Table.read().csv("products.csv");
// Create a Selection for Price greater than 800
Selection premiumSelection = products.doubleColumn("Price")
.____(____);
// Filter the products table using the Selection
Table premiumProducts = products.____(____);
// Print the row count of premium products
System.out.println("Number of premium products: " + premiumProducts.____());
// Print the mean price of premium products
DoubleColumn premiumPrices = premiumProducts.doubleColumn("Price");
System.out.println("Average price of premium products: $" + premiumPrices.____());
} catch (Exception e) {
System.err.println("Error reading CSV files: " + e.getMessage());
}
}
}