Methods for Finding and Checking Data
After calculating the marks, we may want to check whether certain values exist, whether duplicates are present, or whether some values are missing.
isin(): The isin() method checks whether each value in the Series is present in a given list or collection.
For example:
marks = pd.Series([70, 80, 90, 60])
marks.isin([70, 90])
output:
0 True
1 False
2 True
3 False
dtype: bool
It returns True for values that are present in the given list and False for values that are not present.
This is useful when we want to filter or check for specific values.
between(): The between() method checks whether each value falls within a given range.
For example:
marks = pd.Series([40, 55, 70, 85, 95])
marks.between(50, 90)
output:
0 False
1 True
2 True
3 True
4 False
dtype: bool
Here, values between 50 and 90 return True.
duplicated(): The duplicated() method identifies duplicate values in the Series.
For example:
marks = pd.Series([80, 90, 80, 70])
marks.duplicated()
output:
0 False
1 False
2 True
3 False
dtype: bool
Here, the second 80 is marked as True because it is a duplicate of the earlier 80.
isna(): The isna() method checks for missing values in the Series.
For example:
marks = pd.Series([85, 72, None, 90])
marks.isna()
output:
0 False
1 False
2 True
3 False
dtype: bool
It returns True where a value is missing and False where a value is present.
isnull(): The isnull() method works the same way as isna().
For example:
marks = pd.Series([85, None, 90])
marks.isnull()
output:
0 False
1 True
2 False
dtype: bool
Both isna() and isnull() are commonly used to identify missing values.
notna(): The notna() method does the opposite of isna(). It returns True where a value is present and False where a value is missing.
For example:
marks = pd.Series([85, None, 90])
marks.notna()
output:
0 True
1 False
2 True
dtype: bool
So we can remember:
isna() → checks missing values
notna() → checks non-missing values
notnull(): The notnull() method works the same way as notna().
For example:
marks = pd.Series([85, None, 90])
marks.notnull()
output:
0 True
1 False
2 True
dtype: bool