Skip to content
Advertisement

Dropping Multiple Columns from a dataframe

I know how to drop columns from a data frame using Python. But for my problem the data set is vast, the columns I want to drop are grouped together or are basically singularly spread out across the column heading axis. Is there a shorter way to slice or drop all the columns with fewer lines of code rather than to write it out like how I have done. The way I have done it here works but I would like a more summarized way.

The flight_data_copy_final is the variable in which it should be stored.

Here’s my code:

JavaScript

Advertisement

Answer

To delete multiple columns at the same time in pandas, you could specify the column names as shown below. The option inplace=True is needed if one wants the change affected column in the same dataframe. Otherwise remove it.

JavaScript

Source: Python Pandas – Deleting multiple series from a data frame in one command

Advertisement