DataFrame 列名称与 .(dot) 冲突 [英] DataFrame columns names conflict with .(dot)
本文介绍了DataFrame 列名称与 .(dot) 冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 DataFrame df
有这个架构:
I have a DataFrame df
which has this schema:
root
|-- person.name: string (nullable = true)
|-- person: struct (nullable = true)
| |-- age: long (nullable = true)
| |-- name: string (nullable = true)
当我执行 df.select("person.name")
时,我显然从 person
获取子字段 name
.如何选择 person.name
列?
When I do df.select("person.name")
I obviously fetch the sub-field name
from person
. How could I select the column person.name
?
推荐答案
对于包含 .(dot)
的列名,您可以使用 `
字符将列名
For the column name that contains .(dot)
you can use the `
character to enclose the column name
df.select("`person.name`")
这将选择外部字符串 person.name: string (nullable = true)
还有df.select("person.name")
这会得到人名,即结构体
This gets the person name which is struct
|-- person: struct (nullable = true)
| |-- age: long (nullable = true)
如果你有一个列名,你可以在列名前面加上`字符
"`" + columnName + "`"
我希望这有帮助!
这篇关于DataFrame 列名称与 .(dot) 冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文