ComeçarComece de graça

Table filtering

Now that you have the basic product catalog loaded, the startup wants to focus on premium products for their advanced training courses. You need to identify which products are considered "premium" (priced above $800) and create a filtered dataset for the marketing team.

The Table, DoubleColumn, and Selection classes have been imported for you.

Este exercício faz parte do curso

Importing Data in Java

Ver curso

Instruções do exercício

  • Create a Selection for "Price" greater than 800.
  • Filter the products table using the Selection.
  • Print the row count of premium products.
  • Print the mean price of premium products.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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());
		}
    }
}
Editar e executar o código