Skip to content
Advertisement

I want to groupby id and count the unique grade and return max

I have this data and try to solve the following question.

DataFrame_from_Scratch = spark.createDataFrame(values, columns) DataFrame_from_Scratch.show()

JavaScript
  1. groupby id and count unique grade
  2. what is the maximum
  3. groupby id and date and how many unique date is there

Advertisement

Answer

Your implementation for the 1st question is correct. Not sure what exactly your question is seeking as an answer

But nevertheless, below are the answer for other sub-parts –

Data Preparation

JavaScript

Unique Grade Counts

JavaScript

Maximum – Assuming Max Date

JavaScript

Unique Dates

Not sure about the intention behind this , as this does not makes sense based on your dataset as your granularity level is – id & Date

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement