dng
dng

Reputation: 521

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

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

Upvotes: 24

Views: 26117

Answers (1)

zero323
zero323

Reputation: 330413

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__

Upvotes: 45

Related Questions