Files changed (1) hide show
  1. README.me +0 -251
README.me CHANGED
@@ -1,254 +1,3 @@
1
- # 📊 Exploratory Data Analysis (EDA) – E-Commerce Customer Behavior Dataset
2
-
3
- This project performs a full Exploratory Data Analysis (EDA) on an e-commerce customer behavior dataset.
4
- The goal is to explore patterns, detect anomalies, generate insights, and answer research questions using visualizations.
5
-
6
- ---
7
-
8
- # ## 1. 📦 Dataset Loading
9
-
10
- ```python
11
- import pandas as pd
12
-
13
- df = pd.read_csv("ecommerce_customer_behavior_dataset.csv")
14
- df.head()
15
- ````
16
-
17
- # ## 2. 🧹 Data Cleaning
18
-
19
- df.isnull().sum()
20
- df.duplicated().sum()
21
- df['Date'] = pd.to_datetime(df['Date'], errors='coerce')
22
-
23
- df.describe()
24
- df['Age'].describe()
25
- df['Session_Duration_Minutes'].describe()
26
- df['Delivery_Time_Days'].describe()
27
-
28
- df = df[df['Age'] > 0]
29
- df = df[df['Session_Duration_Minutes'] >= 0]
30
- df = df[df['Delivery_Time_Days'] >= 0]
31
-
32
- df = df.drop_duplicates()
33
-
34
- ### ✔️ Summary of Cleaning Steps
35
-
36
- I performed several data cleaning steps to ensure the dataset is consistent and ready for analysis:
37
-
38
- 1. **Missing Values**
39
- Checked with `df.isnull().sum()`
40
- → No missing values, so no filling/removal was needed.
41
-
42
- 2. **Duplicate Rows**
43
- Checked with `df.duplicated().sum()`
44
- → No duplicates found.
45
-
46
- 3. **Parsing Dates**
47
- Converted `Date` column to datetime for better analysis.
48
-
49
- 4. **Scaling / Normalization Issues**
50
- Reviewed distributions using `df.describe()`
51
- → All numeric columns were within reasonable ranges.
52
-
53
- 5. **Inconsistencies / Typos**
54
- Verified `Age`, `Session_Duration_Minutes`, and `Delivery_Time_Days`
55
- → No negative or impossible values.
56
-
57
- 6. **Final Result**
58
- The cleaned dataset (`df`) is ready for deeper EDA and modeling.
59
-
60
-
61
- # ## 3. 🚨 Outlier Detection & Handling
62
-
63
- cols = ['Total_Amount', 'Unit_Price', 'Session_Duration_Minutes']
64
-
65
- for col in cols:
66
- print(f"---- {col} ----")
67
- print(df[col].describe())
68
-
69
- Q1 = df[col].quantile(0.25)
70
- Q3 = df[col].quantile(0.75)
71
- IQR = Q3 - Q1
72
-
73
- lower = Q1 - 1.5 * IQR
74
- upper = Q3 + 1.5 * IQR
75
-
76
- outliers = df[(df[col] < lower) | (df[col] > upper)]
77
- print(f"Outliers count: {outliers.shape[0]}\n")
78
-
79
- ### Summary
80
-
81
- * Outliers were detected in **Total_Amount**, **Unit_Price**, and **Session_Duration_Minutes**.
82
- * In an e-commerce dataset, high purchases or expensive items are **expected business behavior**.
83
- * **Decision:** Outliers were **kept** because they represent real customer actions, not errors.
84
-
85
- # ## 4. 📈 Descriptive Statistics
86
-
87
- df.describe()
88
-
89
- mean_values = df.mean(numeric_only=True)
90
- median_values = df.median(numeric_only=True)
91
-
92
- print("Mean values:\n", mean_values)
93
- print("\nMedian values:\n", median_values)
94
-
95
- correlations = df.corr(numeric_only=True)
96
- print("\nCorrelations:\n", correlations)
97
- ```
98
-
99
- ### ✔️ Key Insights
100
-
101
- * Average customer age ≈ **35 years**.
102
- * Large gap between **mean** and **median** in `Unit_Price` and `Total_Amount` shows **expensive products skewing the average**.
103
- * Most customers buy **2 items** on average.
104
- * Strong correlation between:
105
-
106
- * **Unit_Price → Total_Amount** (≈ 0.79)
107
- * **Quantity → Total_Amount** (≈ 0.33)
108
- * Most other correlations are weak, meaning features behave independently.
109
-
110
- ---
111
-
112
- # ## 5. 📊 Visualizations
113
-
114
- import matplotlib.pyplot as plt
115
- import seaborn as sns
116
-
117
- plt.figure(figsize=(6,4))
118
- sns.histplot(df['Age'], bins=20, kde=True)
119
- plt.title("Distribution of Customer Age")
120
- plt.xlabel("Age")
121
- plt.ylabel("Count")
122
- plt.show()
123
-
124
- plt.figure(figsize=(6,4))
125
- sns.histplot(df['Total_Amount'], bins=30, kde=True)
126
- plt.title("Distribution of Total Purchase Amount")
127
- plt.xlabel("Total Amount")
128
- plt.ylabel("Count")
129
- plt.show()
130
-
131
- plt.figure(figsize=(6,4))
132
- sns.scatterplot(x=df['Unit_Price'], y=df['Total_Amount'])
133
- plt.title("Relationship Between Unit Price and Total Amount")
134
- plt.xlabel("Unit Price")
135
- plt.ylabel("Total Amount")
136
- plt.show()
137
-
138
- plt.figure(figsize=(6,4))
139
- sns.histplot(df['Session_Duration_Minutes'], bins=20, kde=True)
140
- plt.title("Distribution of Session Duration")
141
- plt.xlabel("Session Duration (minutes)")
142
- plt.ylabel("Count")
143
- plt.show()
144
- ```
145
-
146
- ### Resulting Plots
147
-
148
- #### Age Distribution
149
-
150
- ![Age Distribution](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/Ggn9pHkU5v1ltD7MZGanD.png)
151
-
152
- #### Total Purchase Amount
153
-
154
- ![Total Amount](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/7Xe3XztuZ-QwjaSqePDjj.png)
155
-
156
- ---
157
-
158
- # ## 6. Research Questions & Answers
159
-
160
- The following questions were formulated to uncover insights and patterns in customer behavior.
161
-
162
- ---
163
-
164
- # ### **RQ1: Is there a relationship between session duration and total purchase amount?**
165
-
166
- plt.figure(figsize=(6,4))
167
- sns.scatterplot(x=df['Session_Duration_Minutes'], y=df['Total_Amount'])
168
- plt.title("Session Duration vs Total Amount")
169
- plt.xlabel("Session Duration (minutes)")
170
- plt.ylabel("Total Amount")
171
- plt.show()
172
- ```
173
-
174
- ![Session Duration vs Total Amount](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/-nuJodJGzZoUyAjwJuE8b.png)
175
-
176
- **Insight:**
177
- There is **no strong visible correlation**, but longer sessions tend to produce slightly higher purchases.
178
-
179
- ---
180
-
181
- # ### **RQ2: Do returning customers spend more than new customers?**
182
-
183
- avg_spending = df.groupby('Is_Returning_Customer')['Total_Amount'].mean()
184
- print(avg_spending)
185
- plt.figure(figsize=(6,4))
186
- sns.barplot(x=avg_spending.index, y=avg_spending.values)
187
- plt.title("Average Total Amount: Returning vs New Customers")
188
- plt.xlabel("Is Returning Customer (0 = New, 1 = Returning)")
189
- plt.ylabel("Average Total Amount")
190
- plt.show()
191
- ```
192
-
193
- ![Returning Customers](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/-7ybV7xWakRjx3wWY7s9U.png)
194
-
195
- **Insight:**
196
- Returning customers spend **more on average**, showing customer loyalty has monetary value.
197
-
198
-
199
- # ### **RQ3: Does buying more items lead to a higher total order amount?**
200
-
201
- plt.figure(figsize=(6,4))
202
- sns.scatterplot(x=df['Quantity'], y=df['Total_Amount'])
203
- plt.title("Quantity vs Total Amount")
204
- plt.xlabel("Quantity Purchased")
205
- plt.ylabel("Total Amount")
206
- plt.show()
207
-
208
- ![Quantity vs Amount](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/A-3AOaK997W73S5dGSlvz.png)
209
-
210
- **Insight:**
211
- There is a **clear positive relationship** – buying more items leads to higher spending.
212
-
213
-
214
- # ### **RQ4: What is the age distribution of customers?**
215
-
216
- plt.figure(figsize=(6,4))
217
- sns.histplot(df['Age'], bins=20, kde=True)
218
- plt.title("Age Distribution of Customers")
219
- plt.xlabel("Age")
220
- plt.ylabel("Count")
221
- plt.show()
222
-
223
- ![Age Distribution 2](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/w2eI25NkOf0d-pSC8z48A.png)
224
-
225
- **Insight:**
226
- Most customers are between **25–45 years old**, indicating the site's target demographic.
227
-
228
-
229
- # ## 7. Final Conclusions
230
-
231
- * Dataset is **clean**, consistent, and complete.
232
- * Outliers were analyzed and kept because they represent real business behavior.
233
- * Strong relationships detected between:
234
-
235
- * item price ↔ purchase amount
236
- * quantity ↔ purchase amount
237
- * Returning customers spend more → **valuable for retention strategies**.
238
- * Most buyers are aged 25–45 → **useful for marketing targeting**.
239
-
240
- # **This README fulfills all assignment requirements:**
241
-
242
- ✔ Data cleaning
243
- ✔ Outlier analysis
244
- ✔ Descriptive statistics
245
- ✔ Visualizations
246
- ✔ Research questions
247
- ✔ Answers
248
- ✔ Insights
249
- ✔ Final decisions
250
-
251
-
252
 
253
 
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
 
3