When deleting a column in a DataFrame I use:
del df[\'column_name\']
And this works great. Why can\'t I use the following?
Another way of Deleting a Column in Pandas DataFrame
if you're not looking for In-Place deletion then you can create a new DataFrame by specifying the columns using DataFrame(...)
function as
my_dict = { 'name' : ['a','b','c','d'], 'age' : [10,20,25,22], 'designation' : ['CEO', 'VP', 'MD', 'CEO']}
df = pd.DataFrame(my_dict)
Create a new DataFrame as
newdf = pd.DataFrame(df, columns=['name', 'age'])
You get a result as good as what you get with del / drop