How many customers are represented in an orders dataset? Before counting rows, decide which field identifies what you want to count. A distinct value is one different value in a field, counted once even if it appears in several rows. In pandas, `nunique()` counts distinct values; `value_counts()` shows each value and how often it occurs. section 2.3
Check two customer identifiers
Ask an AI assistant: “Show me pandas code to count distinct `customer_id` and `customer_unique_id` values, then count how many distinct `customer_id` values belong to each `customer_unique_id`.” Run the code and inspect its output rather than assuming the field names answer the business question. One analysis found 99,441 distinct `customer_id` values and 96,096 distinct `customer_unique_id` values; a single `customer_unique_id` was associated with as many as 17 distinct `customer_id` values. section 2.3
import pandas as pd
# Sample DataFrame
data = {'customer_id': [1, 2, 3, 4, 5],
'customer_unique_id': [1001, 1002, 1002, 1004, 1004]}
df = pd.DataFrame(data)
# Check the number of unique values in each column
unique_customer_ids = df['customer_id'].nunique()
unique_customer_unique_ids = df['customer_unique_id'].nunique()
print(f"Unique customer_id values: {unique_customer_ids}")
print(f"Unique customer_unique_id values: {unique_customer_unique_ids}")
# Check the relationship between the two columns
relationship = df.groupby('customer_unique_id')['customer_id'].nunique()
print("\nRelationship between customer_unique_id and customer_id:")
print(relationship)
This pandas example uses `nunique()` for each field and `groupby()` to inspect how their values relate. section 2.3
A distinct-value count does not establish that the underlying records are unique. Check repeated values and sample records before deciding what to count or remove. In review data, a copying glitch could repeat one complaint many times and give it undue weight; slightly altered duplicates may need more than an exact-match check. section 2.3 section 5.2.1


