-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_behavior.py
More file actions
22 lines (16 loc) · 822 Bytes
/
analyze_behavior.py
File metadata and controls
22 lines (16 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pandas as pd
df = pd.read_csv('Bank_Churn.csv')
# Group by Geography and calculate mean for relevant behavior columns
behavior_cols = ['Balance', 'NumOfProducts', 'HasCrCard', 'IsActiveMember', 'Exited']
geo_behavior = df.groupby('Geography')[behavior_cols].mean()
# Add count to see sample size
geo_behavior['CustomerCount'] = df.groupby('Geography').size()
print("Account Behavior by Geography (Mean values):")
print(geo_behavior)
# Median Balance (since it often has many zeros or is skewed)
print("\nMedian Balance by Geography:")
print(df.groupby('Geography')['Balance'].median())
# Percentage of customers with zero balance
zero_balance = df[df['Balance'] == 0].groupby('Geography').size() / df.groupby('Geography').size() * 100
print("\nPercentage of customers with Zero Balance:")
print(zero_balance)