I'm trying to use rand() with a window function to create a random set of numbers per group using the below:
df.withColumn("random_groups", F.rand().over(Window.partitionBy("groups")))
This error is being raised however,
AnalysisException: Expression 'rand(4853692135296631772)' not supported within a window function.
Does anyone have any advice as to what I can do here to get my intended output? It looks like this
ID | groups | random_groups
1 | A | 0.3
2 | A | 0.9
3 | B | 0.8