如何从Spark DataFrame删除列表中给定的多个列名? [英] How to drop multiple column names given in a list from Spark DataFrame?
本文介绍了如何从Spark DataFrame删除列表中给定的多个列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基于n值创建的动态列表.
I have a dynamic list which is created based on value of n.
n = 3
drop_lst = ['a' + str(i) for i in range(n)]
df.drop(drop_lst)
但是上面的方法不起作用.
But the above is not working.
注意:
我的用例需要动态列表.
My use case requires a dynamic list.
如果我只执行以下操作而没有列出
If I just do the below without list it works
df.drop('a0','a1','a2')
如何使拖放功能与列表一起使用?
How do I make drop function work with list?
Spark 2.2似乎没有此功能.有没有一种方法可以使它在不使用select()
的情况下工作?
Spark 2.2 doesn't seem to have this capability. Is there a way to make it work without using select()
?
推荐答案
您可以使用*
运算符将列表的内容作为参数传递给drop()
:
You can use the *
operator to pass the contents of your list as arguments to drop()
:
df.drop(*drop_lst)
这篇关于如何从Spark DataFrame删除列表中给定的多个列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文