pyspark.sql.Row.asDict¶
-
Row.
asDict
(recursive=False)[source]¶ Return as a dict
- Parameters
- recursivebool, optional
turns the nested Rows to dict (default: False).
Notes
If a row contains duplicate field names, e.g., the rows of a join between two
DataFrame
that both have the fields of same names, one of the duplicate fields will be selected byasDict
.__getitem__
will also return one of the duplicate fields, however returned value might be different toasDict
.Examples
>>> Row(name="Alice", age=11).asDict() == {'name': 'Alice', 'age': 11} True >>> row = Row(key=1, value=Row(name='a', age=2)) >>> row.asDict() == {'key': 1, 'value': Row(name='a', age=2)} True >>> row.asDict(True) == {'key': 1, 'value': {'name': 'a', 'age': 2}} True