从大 pandas DataFrame中删除列 [英] Delete column from pandas DataFrame

查看:147
本文介绍了从大 pandas DataFrame中删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DataFrame中删除列时,我使用:

When deleting a column in a DataFrame I use:

del df['column_name']

这样做很棒。为什么我不能使用:

and this works great. Why can't I use:

del df.column_name

由于您可以以 df.column_name 的方式访问列/系列,我希望这可以正常工作。 / em>

As you can access the column/Series as df.column_name, I expect this to work.

推荐答案

很难使 del df.column_name 仅仅是Python中的句法限制的结果。 del df [name] 被转换为 df .__ delitem __(name)在Python的封面下

It's difficult to make del df.column_name work simply as the result of syntactic limitations in Python. del df[name] gets translated to df.__delitem__(name) under the covers by Python

这篇关于从大 pandas DataFrame中删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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