This is an excerpt from Manning's book Spark in Action, Second Edition. Login to get full access to this book.
What is the average enrollment for each school? To compute the average enrollment for each school, per year, you will have to group the dataset by school and year. In the same operation, you can also add the average presence and absence for the school.
To compute the average enrollment for each school, per year, you will have to group the dataset by school and year. In the same operation, you can also add the average presence and absence for the school.
Listing 15.14 Code to compute the average enrollment for each NYC school Dataset<Row> averageEnrollmentDf = masterD f col( "schoolId" ), col( "schoolYear" )) #1 .avg( "enrolled" , "present" , "absent" ) #2 .orderBy( "schoolId" , "schoolYear" ); #3
Dataset<Row> averageEnrollmentDf = masterD f col( "schoolId" ), col( "schoolYear" )) #1 .avg( "enrolled" , "present" , "absent" ) #2 .orderBy( "schoolId" , "schoolYear" ); #3