ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Importing Data in Java

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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 y ejecutar código