Skip to content

Commit 7009703

Browse files
committed
Update 1045. Customers Who Bought All Products.py
1 parent bcee40a commit 7009703

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pandas as pd
2+
3+
# Sample data
4+
customer_data = {'customer_id': [1, 2, 3, 3, 1],
5+
'product_key': [5, 6, 5, 6, 6]}
6+
product_data = {'product_key': [5, 6]}
7+
8+
# Create DataFrames
9+
customer_df = pd.DataFrame(customer_data)
10+
product_df = pd.DataFrame(product_data)
11+
12+
# Get the total number of products
13+
total_products = product_df['product_key'].nunique()
14+
15+
# Count distinct products per customer
16+
customer_purchase = customer_df.groupby('customer_id')['product_key'].nunique()
17+
18+
# Filter customers who bought all products
19+
result = customer_purchase[customer_purchase == total_products].reset_index()
20+
21+
print(result)

0 commit comments

Comments
 (0)