I have a dataframe , which schema is below:
root
|-- school: string (nullable = true)
|-- questionName: string (nullable = true)
|-- difficultyValue: double (nullable = true)
The data is like this:
school | questionName | difficultyValue
school1 | q1 | 0.32
school1 | q2 | 0.13
school1 | q3 | 0.58
school1 | q4 | 0.67
school1 | q5 | 0.59
school1 | q6 | 0.43
school1 | q7 | 0.31
school1 | q8 | 0.15
school1 | q9 | 0.21
school1 | q10 | 0.92
But now I want to partition field "difficultyValue" according to Its value, and convert this dataframe to a new dataframe which schema is following:
root
|-- school: string (nullable = true)
|-- difficulty1: double (nullable = true)
|-- difficulty2: double (nullable = true)
|-- difficulty3: double (nullable = true)
|-- difficulty4: double (nullable = true)
|-- difficulty5: double (nullable = true)
and new data table is here:
school | difficulty1 | difficulty2 | difficulty3 | difficulty4 | difficulty5
school1 | 2 | 3 | 3 | 1 |1
The value of field "difficulty1" is the number of "difficultyValue" < 0.2;
The value of field "difficulty2" is the number of "difficultyValue" < 0.4 and "difficultyValue" >= 0.2;
The value of field "difficulty3" is the number of "difficultyValue" < 0.6 and "difficultyValue" >= 0.4;
The value of field "difficulty4" is the number of "difficultyValue" < 0.8 and "difficultyValue" >= 0.6;
The value of field "difficulty5" is the number of "difficultyValue" < 1.0 and "difficultyValue" >= 0.8;
I don't know how to transform it, what am I supposed to do?