I have a dataframe like this:
+---+-------+--------------+
| id|clicked| features |
+---+-------+--------------+
| 7| 1.0 |(4,[3],[1.0]) |
| 8| 0.0 |(4,[2],[12.0])|
| 9| 0.0 |(4,[3],[0.1]) |
+---+-------+--------------+
and have converted it to a RDD:
Row(id=7, clicked=1.0, features=SparseVector(4, {3: 1.0}))
Row(id=8, clicked=0.0, features=SparseVector(4, {2: 12.0}))
Row(id=9, clicked=0.0, features=SparseVector(4, {3: 0.1}))
Now I want to find the number of exists for each feature. For example, in my dataframe/rdd, features column contains 5 features (0 to 4). Since feature in index 0, 1, and 4 do not contain any values, their amounts are 0. And feature index 2 is 1, feature index 3 is 2.
I want get that information within a dictionary data structure. How to do it?
{0:0, 1:0, 2:1, 3:2, 4:0}
I'm using PySpark, but an answer using Scala is also fine.