Filtering columns
As a grocery inventory analyst, you need to clean your inventory data to identify perishable items at risk of spoilage. Raw inventory data often includes irrelevant categories and inaccurate stock levels. To clean this data, you'll filter for the "Fruits & Vegetables" category and high stock levels (over 50 units). This process removes non-perishable items and low-stock products, giving you a clean dataset of fruits and vegetables with potential oversupply issues. By cleaning and focusing your data, you can quickly identify which perishable items need immediate attention.
이 연습은 강의의 일부입니다
Cleaning Data in Java
연습 안내
- Check if the integer column
Stock_Quantityis greater than 50. - Check if the string column
Categoryis equal toFruits & Vegetables. - Filter
inventorybyhighQuantity. - Add a filter condition for
fruitsAndVegetables.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
public class GroceryDataFiltering {
public static void main(String[] args) {
Table inventory = Table.read().csv("grocery_inventory.csv");
// Check if the integer column is greater than 50
Selection highQuantity = inventory.____("Stock_Quantity").____(50);
// Check if the string column is equal to Fruits & Vegetables
Selection fruitsAndVegetables = inventory.____("Category").____("Fruits & Vegetables");
// Filter inventory by highQuantity
Table highQuantityTable = inventory.____(highQuantity
// Add a filter for fruitsAndVegetables
.____(fruitsAndVegetables))
.sortDescendingOn("Stock_Quantity");
System.out.println("High quantity fruits and vegetables:");
System.out.println(highQuantityTable.selectColumns("Product_Name", "Stock_Quantity").first(10));
}
}