无法使用Spark Concat方法从列表中创建新列?

发布于 2025-02-04 05:02:51 字数 709 浏览 4 评论 0原文

我有以下数据框架,其中我试图通过从列表中串联名称来创建一个新列

df=

----------------------------------
| name| department|  state| id| hash
------+-----------+-------+---+----
James|  Sales1   |null   |101|4df2
Maria|  Finance  |       |102|5rfg
Jen  |           |NY2    |103|234

key_list=['name','state','id']

df.withColumn('prim_key', concat(*key_list)
df.show()

,但是上面返回相同的结果,

----------------------------------
| name| department|  state| id| hash
------+-----------+-------+---+----
James|  Sales1   |null   |101|4df2
Maria|  Finance  |       |102|5rfg
Jen  |           |NY2    |103|234


我怀疑这可能是由于DF中的列名中的空间所致。因此,我使用Trim删除了列名称中的所有空间,但没有运气。它返回了相同的结果

解决方案吗?

i have below data frame in which i am trying to create a new column by concatinating name from a list

df=

----------------------------------
| name| department|  state| id| hash
------+-----------+-------+---+----
James|  Sales1   |null   |101|4df2
Maria|  Finance  |       |102|5rfg
Jen  |           |NY2    |103|234

key_list=['name','state','id']

df.withColumn('prim_key', concat(*key_list)
df.show()

but above return the same result

----------------------------------
| name| department|  state| id| hash
------+-----------+-------+---+----
James|  Sales1   |null   |101|4df2
Maria|  Finance  |       |102|5rfg
Jen  |           |NY2    |103|234


i suspecting it might be due to space in the column names in DF. so i used trim to remove all space in column names, but no luck . it returning the same result

Any solution to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音栖息无 2025-02-11 05:02:51

我发现...问题是由于将结果分配给新的或现有的DF

df=df.withColumn('prim_key', concat(*key_list)

i found it... the issue was due to assigning the result to new or existing df

df=df.withColumn('prim_key', concat(*key_list)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文