When deleting a column in a DataFrame I use:
del df[\'column_name\']
And this works great. Why can\'t I use the following?
If your original dataframe df
is not too big, you have no memory constraints, and you only need to keep a few columns, or, if you don't know beforehand the names of all the extra columns that you do not need, then you might as well create a new dataframe with only the columns you need:
new_df = df[['spam', 'sausage']]