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. 
1 Answer
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!
1 Comment
G. Anderson
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
baby_namesDataFrame has no column'Year'.