Skip to main content

asDict

Returns the Row as Dict[str, Any].

Syntax

asDict(recursive: bool = False)

Parameters

Parameter

Type

Description

recursive

bool, optional

Turns the nested Rows to dict (default: False).

Returns

Dict[str, Any]

Notes

If a row contains duplicate field names, for example, the rows of a join between two DataFrame that both have the fields of same names, one of the duplicate fields will be selected by asDict. __getitem__ will also return one of the duplicate fields, however returned value might be different to asDict.

Examples

Python
from pyspark.sql import Row
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