Q:

How to determine whether a Pandas Column contains a particular value?

0

Columns are the different fields that contain their particular values when we create a DataFrame. We can perform certain operations on both rows & column values. Here, we are going to check the whether a value is present in a column or not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Let us understand with the help of an example,

# Import pandas Package
import pandas as pd

# Creating dictionary
d = {
    'Name':['Ankit', 'Tushar', 'Saloni','Jyoti', 'Anuj', 'Rajat'],
    'Age':[23, 21, 22, 21, 24, 25],
    'University':['BHU', 'JNU', 'DU', 'BHU', 'Geu', 'Geu']
}

# Creating a Dataframe
df = pd.DataFrame(d,index = ['a', 'b', 'c', 'd', 'e', 'f'])

print("Created Dataframe:\n", df)
# check 'Jyoti' exist in DataFrame or not

if 'Jyoti' in df.values :
   print("\nYes,'Jyoti' is Present in DataFrame")
else :
   print("\nSorry!, This value does not exists in Dataframe")

Output:

Example: determine Pandas Column contains a particular value

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now