I've the following code:
val df = sqlContext.sql("SELECT Transaction_ID,Product_ID FROM Transactions as tmp")
val rawDict = df.select('Product_ID).distinct().sort('Product_ID)
val dictCounts = rawDict.groupBy('Product_ID).count().filter(col("count") >= 2)
val sigCounts = dictCounts.filter('count === 1)
val dupCounts = dictCounts.filter('count > 1)
val sigDescs = rawDict.join(sigCounts, "Product_ID").drop('count)
val invoiceToStockCode = df.select('Transaction_ID, 'Product_ID).distinct()
val baskets = invoiceToStockCode.groupBy('Transaction_ID).agg(collect_list('Product_ID).as('StockCodes)).cache()
And I'm trying to extract some association rules. For that I need to guarantee that all the transactions are groupped by more than one product. But with my code I'm getting transaction with only one product.
How can I filter that?
Thanks!
Although I'm no 100% sure I got your requirement, I think this should work: