[英]How can I delete a dataframe column by name if the name is a variable in a loop?
I have a loop I created to iterate through the column names and delete them in some cases.我创建了一个循环来遍历列名并在某些情况下删除它们。 I'm trying this code below but it won't work.
我正在尝试下面的代码,但它不起作用。 I'm unable to use call the dataframe column based on a variable name.
我无法使用基于变量名称调用数据框列。 It's expecting the actual name.
它正在等待实际名称。 Is there any way around this?
有没有办法解决?
for name, values in (df.iteritems())
.....
.....
del df[name]
Use drop function使用拖放功能
list =['list of columns']
for col in list:
df.drop(col,axis=1,inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.