Pandas DataFrame pop() method with examples

Spread the love

The pop() method in pandas is used to delete a column from a dataframe. The column name that is passed to the function is dropped from the dataframe and returned as series.

Syntax –


Example –

Let’s read a dataset to work with.

import pandas as pd

df = pd.read_csv(url)

Now, Let’s say you want to delete the pH column. For that you can use the pop method.

# delete the pH column
ph = df.pop('pH')

Now if you check the dataframe you will see that pH column has been deleted.


Rating: 1 out of 5.

Leave a Reply