1# Let df be a dataframe
2# Let new_df be a dataframe after dropping a column
3
4new_df = df.drop(labels='column_name', axis=1)
5
6# Or if you don't want to change the name of the dataframe
7df = df.drop(labels='column_name', axis=1)
8
9# Or to remove several columns
10df = df.drop(['list_of_column_names'], axis=1)
11
12# axis=0 for 'rows' and axis=1 for columns
1df = pd.DataFrame(np.arange(12).reshape(3, 4),
2... columns=['A', 'B', 'C', 'D'])
3>>> df
4 A B C D
50 0 1 2 3
61 4 5 6 7
72 8 9 10 11
8
9Drop columns
10>>> df.drop(['B', 'C'], axis=1)
11 A D
120 0 3
131 4 7
142 8 11
15>>> df.drop(columns=['B', 'C'])
16 A D
170 0 3
181 4 7
192 8 11
1>>> df.drop(index='cow', columns='small')
2 big
3lama speed 45.0
4 weight 200.0
5 length 1.5
6falcon speed 320.0
7 weight 1.0
8 length 0.3
9