9 | Find the average scores of students of different genders and subjects

Requirement description: Student performance analysis

Background:
We have a set of grade data of students, which includes the student's name, gender, and subject, and we need to analyze the average marks of students of different genders and different subjects.

Functional requirements:

  1. Get student performance data from the data source, including student name, gender, and subject.
  2. Use Spark for data processing to group student data by gender and subjects.
  3. Calculate the average score of students for each gender and subject combination to two decimal places.
  4. Output the calculated average score along with gender and subject information.
  5. Results should be presented in an easy-to-understand manner, including gender, subject, and average score.
  6. After performing the calculation, close the Spark context.

enter:

  • Student performance data set, including student name, gender, and subject.

Output:

  • A clearly readable list of average scores for each gender and subject combination.
package com.bigdata;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Tuple2;
import scala.Tuple3;

import java.text.DecimalFormat;
import java.util.Arrays;

public class StudentScoreAnalysis {
    public static void main(String[] args) {
        // 创建Spark配置
        SparkCon

Guess you like

Origin blog.csdn.net/weixin_44510615/article/details/132635655