When deleting a column in a DataFrame I use:
del df['column_name']
And this works great. Why can't I use the following?
del df.column_name
As you can access the column/Series as df.column_name
, I expect this to work.
Answer
As you've guessed, the right syntax is
del df['column_name']
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.
No comments:
Post a Comment