部門分析
你最初的分析讓人資團隊印象深刻!現在他們想更深入了解各部門的洞見。主管團隊正在規劃明年的預算分配,需要掌握不同部門的薪資分布狀況。他們特別關注同時具備高平均薪資、且資深員工(年齡 40+)人數也不少的部門。
Table、Selection,以及彙總函式(mean、count、max)已為你匯入。
本練習屬於課程
Java 中的資料匯入
練習說明
- 以
mean、count、max彙總"Salary"。 - 篩選年齡 40+ 的員工。
- 先依
"Department"排序,再依"Salary"由高到低排序。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
public class DepartmentAnalysis {
public static void main(String[] args) {
try {
Table highEarners = Table.read().csv("top_10_earners.csv");
// Summarize Salary with mean, count, and max
Table salarySummary = highEarners.____("____",
mean, count, max).apply();
System.out.println("Salary Summary:");
System.out.println(salarySummary);
// Filter for employees aged 40+
Table seniorEmployees = highEarners.where(
highEarners.intColumn("____").isGreaterThanOrEqualTo(____));
// Sort by Department, then Salary descending
Table sortedSeniors = seniorEmployees.____("Department")
.sortDescendingOn("Salary");
System.out.println("\nSenior Employees (40+) by Department:");
System.out.println(sortedSeniors);
} catch (Exception e) {
System.err.println("Error reading CSV files: " + e.getMessage());
}
}
}