如何从 Spark DataFrame 中删除列表中给出的多个列名? [英] How to drop multiple column names given in a list from Spark DataFrame?

查看:64
本文介绍了如何从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆