0

I'm using the function del df['column name'] to delete the column in Pandas but there is the error as the attached picture. I have no idea why it does not work. Much appreciated for any help to solve the problem. enter image description here

1
  • 6
    It says your baby_names DataFrame has no column 'Year'. Commented Feb 6, 2020 at 17:41

1 Answer 1

2

You should use the drop method instead.

df.drop(columns='column_name')

And if you want to chage the original Dataframe you should add the inplace=True as an argument to the method.

Also, avoid posting pictures if possible. Posting the written code is often more usufel and makes it easier for someone to help you!

Sign up to request clarification or add additional context in comments.

1 Comment

While this is useful information and definitely the right way to delete a column, have you verified that this works when the del method throws a KeyError in pandas to be sure it actually answers the question? If not, this would be better as a comment. See also: Why do I need 50 reputation to comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.