将行返回为 Dict[str, Any].
Syntax
asDict(recursive: bool = False)
参数
| 参数 | 类型 | Description |
|---|---|---|
recursive |
bool,可选 | 将嵌套行转为听写(默认值:False)。 |
退货
Dict[str, Any]
注释
例如,如果某一行包含重复的字段名称,则两个数据帧之间具有相同名称的字段之间的联接行,则将选择 asDict其中一个重复字段。
__getitem__ 还将返回重复字段之一,但返回的值可能不同于 asDict。
示例
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