Pandas Series property is_unique in Python
The Pandas Series property is_unique used to determine whether a Series object contain an unique elements. It returns boolean value either True or False.
Syntax
 1 Series.is_unique
is_unique property
 1 import pandas as pd
 2 
 3 ser1 = pd.Series([1, 2, 3, 4, 5, 2])
 4 res1 = ser1.is_unique
 5 print('Is Series elements are unique :')
 6 print(res1)
 7 
 8 ser2 = pd.Series([1, 2, 3, 4, 5])
 9 res2 = ser2.is_unique
 10 print('Is Series elements are unique :')
 11 print(res2)
In the above example, a Series object is created by passing an array that has duplicate and unique elements. The Series object property is_unique property is accessed that determine individual Series object and returns the result that assigned to the variable that will be printed on console.
Output
 1 Is Series elements are unique :
 2 False
 3 Is Series elements are unique :
 4 True

Index with strings

Index with strings
 1 import pandas as pd
 2 
 3 index = pd.Index(['Apple', 'banana', 'kiwi', 'apple', 'avocado'])
 4 
 5 print('The original index object :')
 6 print(index)
 7 
 8 print('Is Index includes unique elements ?')
 9 print(index.is_unique)
In the above example, an Index object is created by passing an array of string. A is_unique property is accessed that returns boolean value True, as it compares elements with case sensitive.
Output
 1 The original index object :
 2 Index(['Apple', 'banana', 'kiwi', 'apple', 'avocado'], dtype='object')
 3 
 4 Is Index includes unique elements ?
 5 True

Index with duplicate strings

Index with duplicate strings
 1 import pandas as pd
 2 
 3 index = pd.Index(['apple', 'banana', 'kiwi', 'apple', 'avocado'])
 4 
 5 print('The original index object :')
 6 print(index)
 7 
 8 print('Is Index includes unique elements ?')
 9 print(index.is_unique)
In the above example, a is_unique property is accessed that returns boolean value False, as Index object includes duplicate string value.
Output
 1 The original index object :
 2 Index(['apple', 'banana', 'kiwi', 'apple', 'avocado'], dtype='object')
 3 
 4 Is Index includes unique elements ?
 5 False
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us