How to determine whether a Pandas Column Contains a Particular Value?

Spread the love

Problem –

You want to determine whether a pandas column contains a particular value.

Solution –

Read a dataset to work with.

import pandas as pd

url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/clothing_store_sales.csv'
df = pd.read_csv(url)
df.head()

Let’s say you want to find out whether Discover is in the Method of Payment or not? To do that you have to write.

'Discover' in df['Method of Payment'].values

output - True

Let’s say now I want to check if Rupay is in Method of payments or not?

'Rupay' in df['Method of Payment'].values

output - False

You can also use unique method in pandas to find all the unique values in a column.

df['Method of Payment'].unique()

Rating: 1 out of 5.

Leave a Reply