Removing columns from a pandas DataFrame

In this section, we'll look at how to remove columns or rows from a dataset in pandas. We will come to understand the drop() method and the functionality of its parameters in detail.

To start with, we first import the pandas module into our Jupyter notebook:

import pandas as pd

After this, we read our CSV dataset using the following code:

data = pd.read_csv('data-titanic.csv', index_col=3)data.head()

The dataset should look something like the following:

To remove a single column from our dataset, the pandas drop() method is used. The drop() method consists of two parameters. The first parameter is the ...

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.