My Dataframe looks like this
------+-------+
|cat_id|counter|
+------+-------+
| 12| 61060|
| 1| 542118|
| 13| 164700|
| 3| 406622|
| 5| 54902|
| 10| 118281|
| 11| 13658|
| 14| 72229|
| 2| 131206|
+------+-------+
Query to get above data frame is :
grouped_data = dataframe.groupBy("cat_id").agg(count("*").alias("counter"))
Now I need to read values for different cat_id to save it in another database.
The way I can get it done is by using a for loop on my id's
for cat_id in cat_ids_map:
statsCount = grouped_data.select("counter").filter("cat_id = " + cat_id).collect()[0].counter
But I think there can be a better way to read the counter without for loop. Any suggestions would be helpful!!!
Thanks