How can I get from 'pyspark.sql.types.Row' all the columns/attributes name?


Question

I am using the Python API of Spark version 1.4.1.

My row object looks like this :

row_info = Row(name = Tim, age = 5, is_subscribed = false)

How can I get as a result, a list of the object attributes ? Something like : ["name", "age", "is_subscribed"]

1
11
1/28/2016 5:07:59 PM

Accepted Answer

If you don't care about the order you can simply extract these from a dict:

list(row_info.asDict())

otherwise the only option I am aware of is using __fields__ directly:

row_info.__fields__
22
1/28/2016 5:16:32 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon