When a Pandas Series data object is created in Python, is values can be evaluated with respect to duplicate values. Pandas provides several handy functions dealing with duplicate values in Series. unique() returns unique values of the object, value_counts() will list frequency of each unique value, and isin() will return a boolean Series in terms of elements of the Sereis can be found in the specified list. Next we will show you how to implement these functions in Python IDE.
#Import Pandas and Numpy module
import pandas as pd
import numpy as np
#create a Series with duplicate values
S1 = pd.Series([32,19,201,7,32,19])
S1
#output
0 32
1 19
2 201
3 7
4 32
5 19
dtype: int64
#return unique values of the Series
S1.unique()
#result is a Numpy array
array([ 32, 19, 201, 7], dtype=int64)
#count frequency of unique values in the Series
S1.value_counts()
#output, result is a new Series
32 2
19 2
201 1
7 1
Name: count, dtype: int64
#check values of Series are in the specified list
S1.isin([32,19])
#result is a Series with boolean values
0 True
1 True
2 False
3 False
4 True
5 True
dtype: bool
#isin() can be used to filter values, and store to a new Series
S1[S1.isin([32,19])]
#result is a new Series, with fewer elements than original one
0 32
1 19
4 32
5 19
dtype: int64
Click here to download Python Course Source Files !
For online Python training registration, click here ! Pandas provides flexible ways of generating data…
For online Python training registration, click here ! Data frame is the tabular data object…
Click her for course registration ! When a data frame in Python is created via…
We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…