I'm using pyspark dataframe with a goal to get counts of a variable which can be in multiple columns. Wrote a sql query to get this but unable to translate it for dataframes.
Given the below dataframe, need to get counts of "Foo", "Bar", "Air" in Col1, Col2.
+----------+----+-----+
| ID |Col1|Col2 |
+----------+----+-----+
|2017-01-01| Air| Foo |
|2017-01-02| Foo| Bar|
|2017-01-03| Bar| Air |
|2017-01-04| Air| Foo|
|2017-01-09| Bar| Foo|
|2017-01-01|Foo | Bar|
|2017-01-02|Bar | Air|
|2017-01-01|Foo | Air|
|2017-01-02|Foo | Air|
+----------+----+-----+
Expected output
+-------+-----+
|Var . |Count|
+-------+-----+
| Foo| 7 |
| Air| 6 |
| Bar| 5 |
+-------+-----+