Finding distinct values of a column from a sheet of excel file in python

Viewed 879

How can I find the first column's distict values from sheet3 ?

import sys
import pandas as pd


excel_file = "dataset.xlsx"
datasets = pd.ExcelFile(excel_file)

sheet0 = pd.read_excel(datasets, 'Title Sheet')
sheet3 = pd.read_excel(excel_file, sheet_name=3, index_col=0)
sheet4 = pd.read_excel(excel_file, sheet_name=4, index_col=0)
sheet1 = pd.read_excel(excel_file, sheet_name=1, index_col=0)

customer_data = pd.concat([sheet3, sheet4, sheet1])
1 Answers

To get the unique values of the specific sheet, you can do:

unq = sheet3.iloc[:,0].unique()
print(unq)

To get the count of unique values, you can do:

unq = sheet3.iloc[:,0].nunique()
print(unq)
Related