列のフィルタリング
あなたは食料品の在庫アナリストとして、腐敗リスクのある生鮮品を特定するためにデータをクリーニングする必要があります。生の在庫データには、無関係なカテゴリや不正確な在庫数が含まれていることがよくあります。このデータをクリーニングするために、カテゴリが「Fruits & Vegetables」で、在庫数が50を超える商品に絞り込みます。この処理によって非生鮮品や在庫の少ない商品が除外され、過剰供給の可能性がある果物・野菜の整理されたデータセットが得られます。データをクリーニングして焦点を絞ることで、どの生鮮品に早急な対応が必要かを素早く特定できます。
この演習はコースの一部です
Java によるデータクリーニング
演習の手順
- 整数列
Stock_Quantityが50より大きいかどうかを確認します。 - 文字列列
CategoryがFruits & Vegetablesと等しいかどうかを確認します。 highQuantityを使ってinventoryをフィルタリングします。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));
}
}