
Andrew C. answered 04/19/19
Experienced Programming Tutor
This is pretty much due to how the syntax is interpreted for the code that runs under the hood. *** del df['column_name'] *** is translated to *** df.__delitem__(column_name) *** which is a method that DataFrame can utilize. This is not the case for the other example - If you do ***del df.column_name *** you will have deleted the member variable and DataFrame can't handle its custom deletion.
Inner workings aside, for the purposes of deletion it is generally preferred to use *** drop ***
With *** drop *** you can delete multiple rows or columns at once, and you have the option to perform your deletion inplace or not. See below:
Reassigning the dataframe:
*** df = df.drop('column_name' , 1) ***
Where '1' refers to the column axis ('0' for row axis)
Performing the operation inplace:
*** df.drop('column_name, axis=1, inplace=True) ***
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html