df.registerTempTable('df')
with_category_means = sqlContext.sql(
    'select *, mean(Values) OVER (PARTITION BY Category) as category_mean from df'
    )
Pandas-style transform of grouped data on pyspark DataFrame