I have two dataframes, df1
and df2
, and I'd like to add a new column to the second one. This new column should be the average of a column from the first dataframe. Something like this:
df1 df2 df2
userid count value userid count userid count value
11 2 5 10 1 10 1 5
22 3 4 20 1 ======> 20 1 5
33 5 6 30 1 30 1 5
I'm trying
df2 = df2.withColumn("value", avg(df1.col("value")));
which is not working. How can I do this? Thank you!