Skip to main content

df.drop()

df.drop(columns=column_name or [col_1_name, ..., col_k_name])

Drops a single column, or every column in a list of column names, from df.

Input:
columns : string or list
Column name(s) to drop.
Returns:
A new DataFrame without the column(s) specified in columns.
Return Type:
DataFrame

pets = pets.assign(New_column_1=['this', 'is', 'a', 'new', 'column', 'I', 'assigned'], 
New_column_2=['this', 'is', 'another', 'new', 'column', 'I', 'assigned'])
pets
IndexIDSpeciesColorWeightAgeIs_CatOwner_CommentNew_column_1New_column_2
0dog_001dogblack405False There are no bad dogs, only bad owners.thisthis
1cat_001catgolden1.50.2TrueMy best birthday present ever!!!isis
2cat_002catblack159True****All you need is love and a cat.****aanother
3dog_002dogwhite802FalseLove is a wet nose and a wagging tail.newnew
4dog_003dogblack250.5FalseBe the person your dog thinks you are.columncolumn
5ham_001hamsterblack13FalseNo, thank you!II
6ham_002hamstergolden0.250.2FalseNo, thank you!assignedassigned
7cat_003catblack100TrueNo, thank you!..
pets = pets.drop(columns=['New_column_1', 'New_column_2'])
pets
IndexIDSpeciesColorWeightAgeIs_CatOwner_Comment
0dog_001dogblack405False There are no bad dogs, only bad owners.
1cat_001catgolden1.50.2TrueMy best birthday present ever!!!
2cat_002catblack159True****All you need is love and a cat.****
3dog_002dogwhite802FalseLove is a wet nose and a wagging tail.
4dog_003dogblack250.5FalseBe the person your dog thinks you are.
5ham_001hamsterblack13FalseNo, thank you!
6ham_002hamstergolden0.250.2FalseNo, thank you!
7cat_003catblack100TrueNo, thank you!