John John - 4 years ago 537
Python Question

Delete column from pandas 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

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download