データクリーニングと拡張
TechCorp は新しい人事システムへの移行を進めています。データセットのクリーニングが必要です。具体的には、データ入力ミスと思われる低給与の外れ値を除去し、新システムで使用しない列を削除し、ボーナスの計算フィールドを追加します。データクリーニングは分析作業の約80%を占めると言われており、非常に重要なスキルです。
Table、Selection、DoubleColumn クラスはあらかじめインポートされています。
この演習はコースの一部です
Java でのデータインポート
演習の手順
- 給与が $40,000 未満の従業員を削除してください。
"JobTitle"列を削除してください。- 給与の5%に相当する
PerformanceBonus列を追加してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
public class DataExploration {
public static void main(String[] args) {
Table employees = Table.read().csv("employees.csv");
// Remove employees with salaries below $40,000
Selection lowSalaries = employees.intColumn("Salary").isLessThan(____);
Table cleanedEmployees = employees.____(lowSalaries);
// Remove the JobTitle column
Table streamlined = cleanedEmployees.____("JobTitle");
DoubleColumn performanceBonus = streamlined.intColumn("Salary").asDoubleColumn()
.map(salary -> salary * 0.05);
performanceBonus.setName("PerformanceBonus");
// Add the PerformanceBonus column
Table enhancedEmployees = streamlined.____(performanceBonus);
System.out.println("Total employees after cleaning: " + enhancedEmployees.rowCount());
System.out.println("\nFirst 5 rows of enhanced dataset:");
System.out.println(enhancedEmployees.first(5));
}
}