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

nise2 picture nise2 · Jan 28, 2016 · Viewed 15.1k times · Source

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"]

Answer

zero323 picture zero323 · Jan 28, 2016

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__