Tuesday 22 August 2023

How to Check for Unique Values in Pandas

Series ‘is_unique’ attribute return True if the series contain unique elements, else False.

 

unique_elements_check.py

import pandas as pd

series1 = pd.Series([2, 3, 5])
series2 = pd.Series([2, 3, 5, 2])

print('is series1 contain duplicates ? ', series1.is_unique)
print('is series2 contain duplicates ? ', series2.is_unique)

 

Output

is series1 contain duplicates ?  True
is series2 contain duplicates ?  False

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment