Aditya Suyal commited on
Commit
4e6d833
·
verified ·
1 Parent(s): c44cdaf

Upload cafe_data_cleaning.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. cafe_data_cleaning.ipynb +2128 -0
cafe_data_cleaning.ipynb ADDED
@@ -0,0 +1,2128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd\n",
10
+ "import numpy as np"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 2,
16
+ "metadata": {},
17
+ "outputs": [],
18
+ "source": [
19
+ "df = pd.read_csv(\"dirty_cafe_sales.csv\")"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": 3,
25
+ "metadata": {},
26
+ "outputs": [
27
+ {
28
+ "data": {
29
+ "text/html": [
30
+ "<div>\n",
31
+ "<style scoped>\n",
32
+ " .dataframe tbody tr th:only-of-type {\n",
33
+ " vertical-align: middle;\n",
34
+ " }\n",
35
+ "\n",
36
+ " .dataframe tbody tr th {\n",
37
+ " vertical-align: top;\n",
38
+ " }\n",
39
+ "\n",
40
+ " .dataframe thead th {\n",
41
+ " text-align: right;\n",
42
+ " }\n",
43
+ "</style>\n",
44
+ "<table border=\"1\" class=\"dataframe\">\n",
45
+ " <thead>\n",
46
+ " <tr style=\"text-align: right;\">\n",
47
+ " <th></th>\n",
48
+ " <th>Transaction ID</th>\n",
49
+ " <th>Item</th>\n",
50
+ " <th>Quantity</th>\n",
51
+ " <th>Price Per Unit</th>\n",
52
+ " <th>Total Spent</th>\n",
53
+ " <th>Payment Method</th>\n",
54
+ " <th>Location</th>\n",
55
+ " <th>Transaction Date</th>\n",
56
+ " </tr>\n",
57
+ " </thead>\n",
58
+ " <tbody>\n",
59
+ " <tr>\n",
60
+ " <th>0</th>\n",
61
+ " <td>TXN_1961373</td>\n",
62
+ " <td>Coffee</td>\n",
63
+ " <td>2</td>\n",
64
+ " <td>2.0</td>\n",
65
+ " <td>4.0</td>\n",
66
+ " <td>Credit Card</td>\n",
67
+ " <td>Takeaway</td>\n",
68
+ " <td>2023-09-08</td>\n",
69
+ " </tr>\n",
70
+ " <tr>\n",
71
+ " <th>1</th>\n",
72
+ " <td>TXN_4977031</td>\n",
73
+ " <td>Cake</td>\n",
74
+ " <td>4</td>\n",
75
+ " <td>3.0</td>\n",
76
+ " <td>12.0</td>\n",
77
+ " <td>Cash</td>\n",
78
+ " <td>In-store</td>\n",
79
+ " <td>2023-05-16</td>\n",
80
+ " </tr>\n",
81
+ " <tr>\n",
82
+ " <th>2</th>\n",
83
+ " <td>TXN_4271903</td>\n",
84
+ " <td>Cookie</td>\n",
85
+ " <td>4</td>\n",
86
+ " <td>1.0</td>\n",
87
+ " <td>ERROR</td>\n",
88
+ " <td>Credit Card</td>\n",
89
+ " <td>In-store</td>\n",
90
+ " <td>2023-07-19</td>\n",
91
+ " </tr>\n",
92
+ " <tr>\n",
93
+ " <th>3</th>\n",
94
+ " <td>TXN_7034554</td>\n",
95
+ " <td>Salad</td>\n",
96
+ " <td>2</td>\n",
97
+ " <td>5.0</td>\n",
98
+ " <td>10.0</td>\n",
99
+ " <td>UNKNOWN</td>\n",
100
+ " <td>UNKNOWN</td>\n",
101
+ " <td>2023-04-27</td>\n",
102
+ " </tr>\n",
103
+ " <tr>\n",
104
+ " <th>4</th>\n",
105
+ " <td>TXN_3160411</td>\n",
106
+ " <td>Coffee</td>\n",
107
+ " <td>2</td>\n",
108
+ " <td>2.0</td>\n",
109
+ " <td>4.0</td>\n",
110
+ " <td>Digital Wallet</td>\n",
111
+ " <td>In-store</td>\n",
112
+ " <td>2023-06-11</td>\n",
113
+ " </tr>\n",
114
+ " </tbody>\n",
115
+ "</table>\n",
116
+ "</div>"
117
+ ],
118
+ "text/plain": [
119
+ " Transaction ID Item Quantity Price Per Unit Total Spent Payment Method \\\n",
120
+ "0 TXN_1961373 Coffee 2 2.0 4.0 Credit Card \n",
121
+ "1 TXN_4977031 Cake 4 3.0 12.0 Cash \n",
122
+ "2 TXN_4271903 Cookie 4 1.0 ERROR Credit Card \n",
123
+ "3 TXN_7034554 Salad 2 5.0 10.0 UNKNOWN \n",
124
+ "4 TXN_3160411 Coffee 2 2.0 4.0 Digital Wallet \n",
125
+ "\n",
126
+ " Location Transaction Date \n",
127
+ "0 Takeaway 2023-09-08 \n",
128
+ "1 In-store 2023-05-16 \n",
129
+ "2 In-store 2023-07-19 \n",
130
+ "3 UNKNOWN 2023-04-27 \n",
131
+ "4 In-store 2023-06-11 "
132
+ ]
133
+ },
134
+ "execution_count": 3,
135
+ "metadata": {},
136
+ "output_type": "execute_result"
137
+ }
138
+ ],
139
+ "source": [
140
+ "df.head()"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": 4,
146
+ "metadata": {},
147
+ "outputs": [
148
+ {
149
+ "data": {
150
+ "text/plain": [
151
+ "(10000, 8)"
152
+ ]
153
+ },
154
+ "execution_count": 4,
155
+ "metadata": {},
156
+ "output_type": "execute_result"
157
+ }
158
+ ],
159
+ "source": [
160
+ "df.shape"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 5,
166
+ "metadata": {},
167
+ "outputs": [
168
+ {
169
+ "name": "stdout",
170
+ "output_type": "stream",
171
+ "text": [
172
+ "<class 'pandas.DataFrame'>\n",
173
+ "RangeIndex: 10000 entries, 0 to 9999\n",
174
+ "Data columns (total 8 columns):\n",
175
+ " # Column Non-Null Count Dtype\n",
176
+ "--- ------ -------------- -----\n",
177
+ " 0 Transaction ID 10000 non-null str \n",
178
+ " 1 Item 9667 non-null str \n",
179
+ " 2 Quantity 9862 non-null str \n",
180
+ " 3 Price Per Unit 9821 non-null str \n",
181
+ " 4 Total Spent 9827 non-null str \n",
182
+ " 5 Payment Method 7421 non-null str \n",
183
+ " 6 Location 6735 non-null str \n",
184
+ " 7 Transaction Date 9841 non-null str \n",
185
+ "dtypes: str(8)\n",
186
+ "memory usage: 625.1 KB\n"
187
+ ]
188
+ }
189
+ ],
190
+ "source": [
191
+ "df.info()"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "execution_count": 6,
197
+ "metadata": {},
198
+ "outputs": [
199
+ {
200
+ "data": {
201
+ "text/plain": [
202
+ "Transaction ID 0\n",
203
+ "Item 333\n",
204
+ "Quantity 138\n",
205
+ "Price Per Unit 179\n",
206
+ "Total Spent 173\n",
207
+ "Payment Method 2579\n",
208
+ "Location 3265\n",
209
+ "Transaction Date 159\n",
210
+ "dtype: int64"
211
+ ]
212
+ },
213
+ "execution_count": 6,
214
+ "metadata": {},
215
+ "output_type": "execute_result"
216
+ }
217
+ ],
218
+ "source": [
219
+ "df.isnull().sum()"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": 7,
225
+ "metadata": {},
226
+ "outputs": [
227
+ {
228
+ "name": "stdout",
229
+ "output_type": "stream",
230
+ "text": [
231
+ "\n",
232
+ "--- Transaction ID ---\n",
233
+ "<StringArray>\n",
234
+ "['TXN_1961373', 'TXN_4977031', 'TXN_4271903', 'TXN_7034554', 'TXN_3160411',\n",
235
+ " 'TXN_2602893', 'TXN_4433211', 'TXN_6699534', 'TXN_4717867', 'TXN_2064365',\n",
236
+ " 'TXN_2548360', 'TXN_3051279', 'TXN_7619095', 'TXN_9437049', 'TXN_8915701',\n",
237
+ " 'TXN_2847255', 'TXN_3765707', 'TXN_6769710', 'TXN_8876618', 'TXN_3709394']\n",
238
+ "Length: 20, dtype: str\n",
239
+ "\n",
240
+ "--- Item ---\n",
241
+ "<StringArray>\n",
242
+ "[ 'Coffee', 'Cake', 'Cookie', 'Salad', 'Smoothie', 'UNKNOWN',\n",
243
+ " 'Sandwich', nan, 'ERROR', 'Juice', 'Tea']\n",
244
+ "Length: 11, dtype: str\n",
245
+ "\n",
246
+ "--- Quantity ---\n",
247
+ "<StringArray>\n",
248
+ "['2', '4', '5', '3', '1', 'ERROR', 'UNKNOWN', nan]\n",
249
+ "Length: 8, dtype: str\n",
250
+ "\n",
251
+ "--- Price Per Unit ---\n",
252
+ "<StringArray>\n",
253
+ "['2.0', '3.0', '1.0', '5.0', '4.0', '1.5', nan, 'ERROR', 'UNKNOWN']\n",
254
+ "Length: 9, dtype: str\n",
255
+ "\n",
256
+ "--- Total Spent ---\n",
257
+ "<StringArray>\n",
258
+ "[ '4.0', '12.0', 'ERROR', '10.0', '20.0', '9.0', '16.0',\n",
259
+ " '15.0', '25.0', '8.0', '5.0', '3.0', '6.0', nan,\n",
260
+ " 'UNKNOWN', '2.0', '1.0', '7.5', '4.5', '1.5']\n",
261
+ "Length: 20, dtype: str\n",
262
+ "\n",
263
+ "--- Payment Method ---\n",
264
+ "<StringArray>\n",
265
+ "['Credit Card', 'Cash', 'UNKNOWN', 'Digital Wallet', 'ERROR', nan]\n",
266
+ "Length: 6, dtype: str\n",
267
+ "\n",
268
+ "--- Location ---\n",
269
+ "<StringArray>\n",
270
+ "['Takeaway', 'In-store', 'UNKNOWN', nan, 'ERROR']\n",
271
+ "Length: 5, dtype: str\n",
272
+ "\n",
273
+ "--- Transaction Date ---\n",
274
+ "<StringArray>\n",
275
+ "['2023-09-08', '2023-05-16', '2023-07-19', '2023-04-27', '2023-06-11',\n",
276
+ " '2023-03-31', '2023-10-06', '2023-10-28', '2023-07-28', '2023-12-31',\n",
277
+ " '2023-11-07', 'ERROR', '2023-05-03', '2023-06-01', '2023-03-21',\n",
278
+ " '2023-11-15', '2023-06-10', '2023-02-24', '2023-03-25', '2023-01-15']\n",
279
+ "Length: 20, dtype: str\n"
280
+ ]
281
+ }
282
+ ],
283
+ "source": [
284
+ "for col in df.columns:\n",
285
+ " print(f\"\\n--- {col} ---\")\n",
286
+ " print(df[col].unique()[:20])"
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": 8,
292
+ "metadata": {},
293
+ "outputs": [],
294
+ "source": [
295
+ "df = df.replace([\"ERROR\", \"UNKNOWN\"], np.nan)"
296
+ ]
297
+ },
298
+ {
299
+ "cell_type": "code",
300
+ "execution_count": 9,
301
+ "metadata": {},
302
+ "outputs": [
303
+ {
304
+ "data": {
305
+ "text/plain": [
306
+ "Transaction ID 0\n",
307
+ "Item 969\n",
308
+ "Quantity 479\n",
309
+ "Price Per Unit 533\n",
310
+ "Total Spent 502\n",
311
+ "Payment Method 3178\n",
312
+ "Location 3961\n",
313
+ "Transaction Date 460\n",
314
+ "dtype: int64"
315
+ ]
316
+ },
317
+ "execution_count": 9,
318
+ "metadata": {},
319
+ "output_type": "execute_result"
320
+ }
321
+ ],
322
+ "source": [
323
+ "df.isnull().sum()"
324
+ ]
325
+ },
326
+ {
327
+ "cell_type": "code",
328
+ "execution_count": 10,
329
+ "metadata": {},
330
+ "outputs": [
331
+ {
332
+ "data": {
333
+ "text/html": [
334
+ "<div>\n",
335
+ "<style scoped>\n",
336
+ " .dataframe tbody tr th:only-of-type {\n",
337
+ " vertical-align: middle;\n",
338
+ " }\n",
339
+ "\n",
340
+ " .dataframe tbody tr th {\n",
341
+ " vertical-align: top;\n",
342
+ " }\n",
343
+ "\n",
344
+ " .dataframe thead th {\n",
345
+ " text-align: right;\n",
346
+ " }\n",
347
+ "</style>\n",
348
+ "<table border=\"1\" class=\"dataframe\">\n",
349
+ " <thead>\n",
350
+ " <tr style=\"text-align: right;\">\n",
351
+ " <th></th>\n",
352
+ " <th>Transaction ID</th>\n",
353
+ " <th>Item</th>\n",
354
+ " <th>Quantity</th>\n",
355
+ " <th>Price Per Unit</th>\n",
356
+ " <th>Total Spent</th>\n",
357
+ " <th>Payment Method</th>\n",
358
+ " <th>Location</th>\n",
359
+ " <th>Transaction Date</th>\n",
360
+ " </tr>\n",
361
+ " </thead>\n",
362
+ " <tbody>\n",
363
+ " <tr>\n",
364
+ " <th>0</th>\n",
365
+ " <td>TXN_1961373</td>\n",
366
+ " <td>Coffee</td>\n",
367
+ " <td>2</td>\n",
368
+ " <td>2.0</td>\n",
369
+ " <td>4.0</td>\n",
370
+ " <td>Credit Card</td>\n",
371
+ " <td>Takeaway</td>\n",
372
+ " <td>2023-09-08</td>\n",
373
+ " </tr>\n",
374
+ " <tr>\n",
375
+ " <th>1</th>\n",
376
+ " <td>TXN_4977031</td>\n",
377
+ " <td>Cake</td>\n",
378
+ " <td>4</td>\n",
379
+ " <td>3.0</td>\n",
380
+ " <td>12.0</td>\n",
381
+ " <td>Cash</td>\n",
382
+ " <td>In-store</td>\n",
383
+ " <td>2023-05-16</td>\n",
384
+ " </tr>\n",
385
+ " <tr>\n",
386
+ " <th>2</th>\n",
387
+ " <td>TXN_4271903</td>\n",
388
+ " <td>Cookie</td>\n",
389
+ " <td>4</td>\n",
390
+ " <td>1.0</td>\n",
391
+ " <td>NaN</td>\n",
392
+ " <td>Credit Card</td>\n",
393
+ " <td>In-store</td>\n",
394
+ " <td>2023-07-19</td>\n",
395
+ " </tr>\n",
396
+ " <tr>\n",
397
+ " <th>3</th>\n",
398
+ " <td>TXN_7034554</td>\n",
399
+ " <td>Salad</td>\n",
400
+ " <td>2</td>\n",
401
+ " <td>5.0</td>\n",
402
+ " <td>10.0</td>\n",
403
+ " <td>NaN</td>\n",
404
+ " <td>NaN</td>\n",
405
+ " <td>2023-04-27</td>\n",
406
+ " </tr>\n",
407
+ " <tr>\n",
408
+ " <th>4</th>\n",
409
+ " <td>TXN_3160411</td>\n",
410
+ " <td>Coffee</td>\n",
411
+ " <td>2</td>\n",
412
+ " <td>2.0</td>\n",
413
+ " <td>4.0</td>\n",
414
+ " <td>Digital Wallet</td>\n",
415
+ " <td>In-store</td>\n",
416
+ " <td>2023-06-11</td>\n",
417
+ " </tr>\n",
418
+ " </tbody>\n",
419
+ "</table>\n",
420
+ "</div>"
421
+ ],
422
+ "text/plain": [
423
+ " Transaction ID Item Quantity Price Per Unit Total Spent Payment Method \\\n",
424
+ "0 TXN_1961373 Coffee 2 2.0 4.0 Credit Card \n",
425
+ "1 TXN_4977031 Cake 4 3.0 12.0 Cash \n",
426
+ "2 TXN_4271903 Cookie 4 1.0 NaN Credit Card \n",
427
+ "3 TXN_7034554 Salad 2 5.0 10.0 NaN \n",
428
+ "4 TXN_3160411 Coffee 2 2.0 4.0 Digital Wallet \n",
429
+ "\n",
430
+ " Location Transaction Date \n",
431
+ "0 Takeaway 2023-09-08 \n",
432
+ "1 In-store 2023-05-16 \n",
433
+ "2 In-store 2023-07-19 \n",
434
+ "3 NaN 2023-04-27 \n",
435
+ "4 In-store 2023-06-11 "
436
+ ]
437
+ },
438
+ "execution_count": 10,
439
+ "metadata": {},
440
+ "output_type": "execute_result"
441
+ }
442
+ ],
443
+ "source": [
444
+ "df.head()"
445
+ ]
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "execution_count": 12,
450
+ "metadata": {},
451
+ "outputs": [
452
+ {
453
+ "data": {
454
+ "text/html": [
455
+ "<div>\n",
456
+ "<style scoped>\n",
457
+ " .dataframe tbody tr th:only-of-type {\n",
458
+ " vertical-align: middle;\n",
459
+ " }\n",
460
+ "\n",
461
+ " .dataframe tbody tr th {\n",
462
+ " vertical-align: top;\n",
463
+ " }\n",
464
+ "\n",
465
+ " .dataframe thead th {\n",
466
+ " text-align: right;\n",
467
+ " }\n",
468
+ "</style>\n",
469
+ "<table border=\"1\" class=\"dataframe\">\n",
470
+ " <thead>\n",
471
+ " <tr style=\"text-align: right;\">\n",
472
+ " <th></th>\n",
473
+ " <th>Missing Count</th>\n",
474
+ " <th>Missing Percentage</th>\n",
475
+ " </tr>\n",
476
+ " </thead>\n",
477
+ " <tbody>\n",
478
+ " <tr>\n",
479
+ " <th>Transaction ID</th>\n",
480
+ " <td>0</td>\n",
481
+ " <td>0.00</td>\n",
482
+ " </tr>\n",
483
+ " <tr>\n",
484
+ " <th>Item</th>\n",
485
+ " <td>969</td>\n",
486
+ " <td>9.69</td>\n",
487
+ " </tr>\n",
488
+ " <tr>\n",
489
+ " <th>Quantity</th>\n",
490
+ " <td>479</td>\n",
491
+ " <td>4.79</td>\n",
492
+ " </tr>\n",
493
+ " <tr>\n",
494
+ " <th>Price Per Unit</th>\n",
495
+ " <td>533</td>\n",
496
+ " <td>5.33</td>\n",
497
+ " </tr>\n",
498
+ " <tr>\n",
499
+ " <th>Total Spent</th>\n",
500
+ " <td>502</td>\n",
501
+ " <td>5.02</td>\n",
502
+ " </tr>\n",
503
+ " <tr>\n",
504
+ " <th>Payment Method</th>\n",
505
+ " <td>3178</td>\n",
506
+ " <td>31.78</td>\n",
507
+ " </tr>\n",
508
+ " <tr>\n",
509
+ " <th>Location</th>\n",
510
+ " <td>3961</td>\n",
511
+ " <td>39.61</td>\n",
512
+ " </tr>\n",
513
+ " <tr>\n",
514
+ " <th>Transaction Date</th>\n",
515
+ " <td>460</td>\n",
516
+ " <td>4.60</td>\n",
517
+ " </tr>\n",
518
+ " </tbody>\n",
519
+ "</table>\n",
520
+ "</div>"
521
+ ],
522
+ "text/plain": [
523
+ " Missing Count Missing Percentage\n",
524
+ "Transaction ID 0 0.00\n",
525
+ "Item 969 9.69\n",
526
+ "Quantity 479 4.79\n",
527
+ "Price Per Unit 533 5.33\n",
528
+ "Total Spent 502 5.02\n",
529
+ "Payment Method 3178 31.78\n",
530
+ "Location 3961 39.61\n",
531
+ "Transaction Date 460 4.60"
532
+ ]
533
+ },
534
+ "execution_count": 12,
535
+ "metadata": {},
536
+ "output_type": "execute_result"
537
+ }
538
+ ],
539
+ "source": [
540
+ "missing_summary = pd.DataFrame({\n",
541
+ " \"Missing Count\": df.isnull().sum(),\n",
542
+ " \"Missing Percentage\": (df.isnull().sum() / len(df) * 100).round(2)\n",
543
+ "})\n",
544
+ "\n",
545
+ "missing_summary"
546
+ ]
547
+ },
548
+ {
549
+ "cell_type": "code",
550
+ "execution_count": 20,
551
+ "metadata": {},
552
+ "outputs": [],
553
+ "source": [
554
+ "# Fill missing values in categorical columns\n",
555
+ "\n",
556
+ "# Item → fill with mode\n",
557
+ "df[\"Item\"] = df[\"Item\"].fillna(df[\"Item\"].mode()[0])\n",
558
+ "\n",
559
+ "# Payment Method → fill with mode\n",
560
+ "df[\"Payment Method\"] = df[\"Payment Method\"].fillna(\n",
561
+ " df[\"Payment Method\"].mode()[0]\n",
562
+ ")\n",
563
+ "\n",
564
+ "# Location → fill missing values with \"Unknown\"\n",
565
+ "df[\"Location\"] = df[\"Location\"].fillna(\"Unknown\")"
566
+ ]
567
+ },
568
+ {
569
+ "cell_type": "code",
570
+ "execution_count": 21,
571
+ "metadata": {},
572
+ "outputs": [
573
+ {
574
+ "data": {
575
+ "text/plain": [
576
+ "Item 0\n",
577
+ "Payment Method 0\n",
578
+ "Location 0\n",
579
+ "dtype: int64"
580
+ ]
581
+ },
582
+ "execution_count": 21,
583
+ "metadata": {},
584
+ "output_type": "execute_result"
585
+ }
586
+ ],
587
+ "source": [
588
+ "df[[\"Item\", \"Payment Method\", \"Location\"]].isnull().sum()"
589
+ ]
590
+ },
591
+ {
592
+ "cell_type": "code",
593
+ "execution_count": 22,
594
+ "metadata": {},
595
+ "outputs": [
596
+ {
597
+ "data": {
598
+ "text/plain": [
599
+ "Location\n",
600
+ "Unknown 3961\n",
601
+ "Takeaway 3022\n",
602
+ "In-store 3017\n",
603
+ "Name: count, dtype: int64"
604
+ ]
605
+ },
606
+ "execution_count": 22,
607
+ "metadata": {},
608
+ "output_type": "execute_result"
609
+ }
610
+ ],
611
+ "source": [
612
+ "df[\"Location\"].value_counts()"
613
+ ]
614
+ },
615
+ {
616
+ "cell_type": "code",
617
+ "execution_count": 23,
618
+ "metadata": {},
619
+ "outputs": [],
620
+ "source": [
621
+ "numeric_columns = [\"Quantity\", \"Price Per Unit\", \"Total Spent\"]\n",
622
+ "\n",
623
+ "for col in numeric_columns:\n",
624
+ " df[col] = pd.to_numeric(df[col], errors=\"coerce\")"
625
+ ]
626
+ },
627
+ {
628
+ "cell_type": "code",
629
+ "execution_count": 24,
630
+ "metadata": {},
631
+ "outputs": [
632
+ {
633
+ "data": {
634
+ "text/plain": [
635
+ "Quantity float64\n",
636
+ "Price Per Unit float64\n",
637
+ "Total Spent float64\n",
638
+ "dtype: object"
639
+ ]
640
+ },
641
+ "execution_count": 24,
642
+ "metadata": {},
643
+ "output_type": "execute_result"
644
+ }
645
+ ],
646
+ "source": [
647
+ "df[numeric_columns].dtypes"
648
+ ]
649
+ },
650
+ {
651
+ "cell_type": "code",
652
+ "execution_count": 25,
653
+ "metadata": {},
654
+ "outputs": [
655
+ {
656
+ "data": {
657
+ "text/plain": [
658
+ "Quantity 479\n",
659
+ "Price Per Unit 533\n",
660
+ "Total Spent 502\n",
661
+ "dtype: int64"
662
+ ]
663
+ },
664
+ "execution_count": 25,
665
+ "metadata": {},
666
+ "output_type": "execute_result"
667
+ }
668
+ ],
669
+ "source": [
670
+ "df[numeric_columns].isnull().sum()"
671
+ ]
672
+ },
673
+ {
674
+ "cell_type": "code",
675
+ "execution_count": 26,
676
+ "metadata": {},
677
+ "outputs": [
678
+ {
679
+ "data": {
680
+ "text/html": [
681
+ "<div>\n",
682
+ "<style scoped>\n",
683
+ " .dataframe tbody tr th:only-of-type {\n",
684
+ " vertical-align: middle;\n",
685
+ " }\n",
686
+ "\n",
687
+ " .dataframe tbody tr th {\n",
688
+ " vertical-align: top;\n",
689
+ " }\n",
690
+ "\n",
691
+ " .dataframe thead th {\n",
692
+ " text-align: right;\n",
693
+ " }\n",
694
+ "</style>\n",
695
+ "<table border=\"1\" class=\"dataframe\">\n",
696
+ " <thead>\n",
697
+ " <tr style=\"text-align: right;\">\n",
698
+ " <th></th>\n",
699
+ " <th>Actual Total</th>\n",
700
+ " <th>Calculated Total</th>\n",
701
+ " </tr>\n",
702
+ " </thead>\n",
703
+ " <tbody>\n",
704
+ " <tr>\n",
705
+ " <th>0</th>\n",
706
+ " <td>4.0</td>\n",
707
+ " <td>4.0</td>\n",
708
+ " </tr>\n",
709
+ " <tr>\n",
710
+ " <th>1</th>\n",
711
+ " <td>12.0</td>\n",
712
+ " <td>12.0</td>\n",
713
+ " </tr>\n",
714
+ " <tr>\n",
715
+ " <th>2</th>\n",
716
+ " <td>NaN</td>\n",
717
+ " <td>4.0</td>\n",
718
+ " </tr>\n",
719
+ " <tr>\n",
720
+ " <th>3</th>\n",
721
+ " <td>10.0</td>\n",
722
+ " <td>10.0</td>\n",
723
+ " </tr>\n",
724
+ " <tr>\n",
725
+ " <th>4</th>\n",
726
+ " <td>4.0</td>\n",
727
+ " <td>4.0</td>\n",
728
+ " </tr>\n",
729
+ " <tr>\n",
730
+ " <th>5</th>\n",
731
+ " <td>20.0</td>\n",
732
+ " <td>20.0</td>\n",
733
+ " </tr>\n",
734
+ " <tr>\n",
735
+ " <th>6</th>\n",
736
+ " <td>9.0</td>\n",
737
+ " <td>9.0</td>\n",
738
+ " </tr>\n",
739
+ " <tr>\n",
740
+ " <th>7</th>\n",
741
+ " <td>16.0</td>\n",
742
+ " <td>16.0</td>\n",
743
+ " </tr>\n",
744
+ " <tr>\n",
745
+ " <th>8</th>\n",
746
+ " <td>15.0</td>\n",
747
+ " <td>15.0</td>\n",
748
+ " </tr>\n",
749
+ " <tr>\n",
750
+ " <th>9</th>\n",
751
+ " <td>20.0</td>\n",
752
+ " <td>20.0</td>\n",
753
+ " </tr>\n",
754
+ " </tbody>\n",
755
+ "</table>\n",
756
+ "</div>"
757
+ ],
758
+ "text/plain": [
759
+ " Actual Total Calculated Total\n",
760
+ "0 4.0 4.0\n",
761
+ "1 12.0 12.0\n",
762
+ "2 NaN 4.0\n",
763
+ "3 10.0 10.0\n",
764
+ "4 4.0 4.0\n",
765
+ "5 20.0 20.0\n",
766
+ "6 9.0 9.0\n",
767
+ "7 16.0 16.0\n",
768
+ "8 15.0 15.0\n",
769
+ "9 20.0 20.0"
770
+ ]
771
+ },
772
+ "execution_count": 26,
773
+ "metadata": {},
774
+ "output_type": "execute_result"
775
+ }
776
+ ],
777
+ "source": [
778
+ "calculated_total = df[\"Quantity\"] * df[\"Price Per Unit\"]\n",
779
+ "\n",
780
+ "comparison = pd.DataFrame({\n",
781
+ " \"Actual Total\": df[\"Total Spent\"],\n",
782
+ " \"Calculated Total\": calculated_total\n",
783
+ "})\n",
784
+ "\n",
785
+ "comparison.head(10)"
786
+ ]
787
+ },
788
+ {
789
+ "cell_type": "code",
790
+ "execution_count": 27,
791
+ "metadata": {},
792
+ "outputs": [
793
+ {
794
+ "data": {
795
+ "text/plain": [
796
+ "np.int64(0)"
797
+ ]
798
+ },
799
+ "execution_count": 27,
800
+ "metadata": {},
801
+ "output_type": "execute_result"
802
+ }
803
+ ],
804
+ "source": [
805
+ "mismatch = (\n",
806
+ " df[\"Total Spent\"].notna()\n",
807
+ " & calculated_total.notna()\n",
808
+ " & (df[\"Total Spent\"] != calculated_total)\n",
809
+ ")\n",
810
+ "\n",
811
+ "mismatch.sum()"
812
+ ]
813
+ },
814
+ {
815
+ "cell_type": "code",
816
+ "execution_count": 28,
817
+ "metadata": {},
818
+ "outputs": [
819
+ {
820
+ "data": {
821
+ "text/html": [
822
+ "<div>\n",
823
+ "<style scoped>\n",
824
+ " .dataframe tbody tr th:only-of-type {\n",
825
+ " vertical-align: middle;\n",
826
+ " }\n",
827
+ "\n",
828
+ " .dataframe tbody tr th {\n",
829
+ " vertical-align: top;\n",
830
+ " }\n",
831
+ "\n",
832
+ " .dataframe thead th {\n",
833
+ " text-align: right;\n",
834
+ " }\n",
835
+ "</style>\n",
836
+ "<table border=\"1\" class=\"dataframe\">\n",
837
+ " <thead>\n",
838
+ " <tr style=\"text-align: right;\">\n",
839
+ " <th></th>\n",
840
+ " <th>Item</th>\n",
841
+ " <th>Quantity</th>\n",
842
+ " <th>Price Per Unit</th>\n",
843
+ " <th>Total Spent</th>\n",
844
+ " </tr>\n",
845
+ " </thead>\n",
846
+ " <tbody>\n",
847
+ " </tbody>\n",
848
+ "</table>\n",
849
+ "</div>"
850
+ ],
851
+ "text/plain": [
852
+ "Empty DataFrame\n",
853
+ "Columns: [Item, Quantity, Price Per Unit, Total Spent]\n",
854
+ "Index: []"
855
+ ]
856
+ },
857
+ "execution_count": 28,
858
+ "metadata": {},
859
+ "output_type": "execute_result"
860
+ }
861
+ ],
862
+ "source": [
863
+ "df.loc[mismatch, [\n",
864
+ " \"Item\",\n",
865
+ " \"Quantity\",\n",
866
+ " \"Price Per Unit\",\n",
867
+ " \"Total Spent\"\n",
868
+ "]].head(20)"
869
+ ]
870
+ },
871
+ {
872
+ "cell_type": "code",
873
+ "execution_count": 29,
874
+ "metadata": {},
875
+ "outputs": [
876
+ {
877
+ "data": {
878
+ "text/plain": [
879
+ "Quantity 3.0\n",
880
+ "Price Per Unit 3.0\n",
881
+ "dtype: float64"
882
+ ]
883
+ },
884
+ "execution_count": 29,
885
+ "metadata": {},
886
+ "output_type": "execute_result"
887
+ }
888
+ ],
889
+ "source": [
890
+ "df[[\"Quantity\", \"Price Per Unit\"]].median()"
891
+ ]
892
+ },
893
+ {
894
+ "cell_type": "code",
895
+ "execution_count": 30,
896
+ "metadata": {},
897
+ "outputs": [],
898
+ "source": [
899
+ "df[\"Quantity\"] = df[\"Quantity\"].fillna(df[\"Quantity\"].median())\n",
900
+ "\n",
901
+ "df[\"Price Per Unit\"] = df[\"Price Per Unit\"].fillna(\n",
902
+ " df[\"Price Per Unit\"].median()\n",
903
+ ")"
904
+ ]
905
+ },
906
+ {
907
+ "cell_type": "code",
908
+ "execution_count": 31,
909
+ "metadata": {},
910
+ "outputs": [
911
+ {
912
+ "data": {
913
+ "text/plain": [
914
+ "Quantity 0\n",
915
+ "Price Per Unit 0\n",
916
+ "dtype: int64"
917
+ ]
918
+ },
919
+ "execution_count": 31,
920
+ "metadata": {},
921
+ "output_type": "execute_result"
922
+ }
923
+ ],
924
+ "source": [
925
+ "df[[\"Quantity\", \"Price Per Unit\"]].isnull().sum()"
926
+ ]
927
+ },
928
+ {
929
+ "cell_type": "code",
930
+ "execution_count": 32,
931
+ "metadata": {},
932
+ "outputs": [],
933
+ "source": [
934
+ "df[\"Total Spent\"] = df[\"Total Spent\"].fillna(\n",
935
+ " df[\"Quantity\"] * df[\"Price Per Unit\"]\n",
936
+ ")"
937
+ ]
938
+ },
939
+ {
940
+ "cell_type": "code",
941
+ "execution_count": 33,
942
+ "metadata": {},
943
+ "outputs": [
944
+ {
945
+ "data": {
946
+ "text/plain": [
947
+ "np.int64(0)"
948
+ ]
949
+ },
950
+ "execution_count": 33,
951
+ "metadata": {},
952
+ "output_type": "execute_result"
953
+ }
954
+ ],
955
+ "source": [
956
+ "df[\"Total Spent\"].isnull().sum()"
957
+ ]
958
+ },
959
+ {
960
+ "cell_type": "code",
961
+ "execution_count": 34,
962
+ "metadata": {},
963
+ "outputs": [],
964
+ "source": [
965
+ "df[\"Transaction Date\"] = pd.to_datetime(\n",
966
+ " df[\"Transaction Date\"],\n",
967
+ " errors=\"coerce\"\n",
968
+ ")"
969
+ ]
970
+ },
971
+ {
972
+ "cell_type": "code",
973
+ "execution_count": 35,
974
+ "metadata": {},
975
+ "outputs": [
976
+ {
977
+ "data": {
978
+ "text/plain": [
979
+ "dtype('<M8[us]')"
980
+ ]
981
+ },
982
+ "execution_count": 35,
983
+ "metadata": {},
984
+ "output_type": "execute_result"
985
+ }
986
+ ],
987
+ "source": [
988
+ "df[\"Transaction Date\"].dtype"
989
+ ]
990
+ },
991
+ {
992
+ "cell_type": "code",
993
+ "execution_count": 36,
994
+ "metadata": {},
995
+ "outputs": [
996
+ {
997
+ "data": {
998
+ "text/plain": [
999
+ "np.int64(460)"
1000
+ ]
1001
+ },
1002
+ "execution_count": 36,
1003
+ "metadata": {},
1004
+ "output_type": "execute_result"
1005
+ }
1006
+ ],
1007
+ "source": [
1008
+ "df[\"Transaction Date\"].isnull().sum()"
1009
+ ]
1010
+ },
1011
+ {
1012
+ "cell_type": "code",
1013
+ "execution_count": 37,
1014
+ "metadata": {},
1015
+ "outputs": [
1016
+ {
1017
+ "data": {
1018
+ "text/plain": [
1019
+ "np.int64(460)"
1020
+ ]
1021
+ },
1022
+ "execution_count": 37,
1023
+ "metadata": {},
1024
+ "output_type": "execute_result"
1025
+ }
1026
+ ],
1027
+ "source": [
1028
+ "df[\"Transaction Date\"].isnull().sum()"
1029
+ ]
1030
+ },
1031
+ {
1032
+ "cell_type": "code",
1033
+ "execution_count": 38,
1034
+ "metadata": {},
1035
+ "outputs": [],
1036
+ "source": [
1037
+ "df = df.dropna(subset=[\"Transaction Date\"]).copy()"
1038
+ ]
1039
+ },
1040
+ {
1041
+ "cell_type": "code",
1042
+ "execution_count": 39,
1043
+ "metadata": {},
1044
+ "outputs": [
1045
+ {
1046
+ "data": {
1047
+ "text/plain": [
1048
+ "np.int64(0)"
1049
+ ]
1050
+ },
1051
+ "execution_count": 39,
1052
+ "metadata": {},
1053
+ "output_type": "execute_result"
1054
+ }
1055
+ ],
1056
+ "source": [
1057
+ "df[\"Transaction Date\"].isnull().sum()"
1058
+ ]
1059
+ },
1060
+ {
1061
+ "cell_type": "code",
1062
+ "execution_count": 40,
1063
+ "metadata": {},
1064
+ "outputs": [
1065
+ {
1066
+ "data": {
1067
+ "text/plain": [
1068
+ "(9540, 8)"
1069
+ ]
1070
+ },
1071
+ "execution_count": 40,
1072
+ "metadata": {},
1073
+ "output_type": "execute_result"
1074
+ }
1075
+ ],
1076
+ "source": [
1077
+ "df.shape"
1078
+ ]
1079
+ },
1080
+ {
1081
+ "cell_type": "code",
1082
+ "execution_count": 41,
1083
+ "metadata": {},
1084
+ "outputs": [
1085
+ {
1086
+ "data": {
1087
+ "text/plain": [
1088
+ "np.int64(0)"
1089
+ ]
1090
+ },
1091
+ "execution_count": 41,
1092
+ "metadata": {},
1093
+ "output_type": "execute_result"
1094
+ }
1095
+ ],
1096
+ "source": [
1097
+ "df.duplicated().sum()"
1098
+ ]
1099
+ },
1100
+ {
1101
+ "cell_type": "code",
1102
+ "execution_count": 42,
1103
+ "metadata": {},
1104
+ "outputs": [
1105
+ {
1106
+ "data": {
1107
+ "text/plain": [
1108
+ "np.int64(0)"
1109
+ ]
1110
+ },
1111
+ "execution_count": 42,
1112
+ "metadata": {},
1113
+ "output_type": "execute_result"
1114
+ }
1115
+ ],
1116
+ "source": [
1117
+ "df[\"Transaction ID\"].duplicated().sum()"
1118
+ ]
1119
+ },
1120
+ {
1121
+ "cell_type": "code",
1122
+ "execution_count": 43,
1123
+ "metadata": {},
1124
+ "outputs": [
1125
+ {
1126
+ "data": {
1127
+ "text/html": [
1128
+ "<div>\n",
1129
+ "<style scoped>\n",
1130
+ " .dataframe tbody tr th:only-of-type {\n",
1131
+ " vertical-align: middle;\n",
1132
+ " }\n",
1133
+ "\n",
1134
+ " .dataframe tbody tr th {\n",
1135
+ " vertical-align: top;\n",
1136
+ " }\n",
1137
+ "\n",
1138
+ " .dataframe thead th {\n",
1139
+ " text-align: right;\n",
1140
+ " }\n",
1141
+ "</style>\n",
1142
+ "<table border=\"1\" class=\"dataframe\">\n",
1143
+ " <thead>\n",
1144
+ " <tr style=\"text-align: right;\">\n",
1145
+ " <th></th>\n",
1146
+ " <th>Transaction ID</th>\n",
1147
+ " <th>Item</th>\n",
1148
+ " <th>Quantity</th>\n",
1149
+ " <th>Price Per Unit</th>\n",
1150
+ " <th>Total Spent</th>\n",
1151
+ " <th>Payment Method</th>\n",
1152
+ " <th>Location</th>\n",
1153
+ " <th>Transaction Date</th>\n",
1154
+ " </tr>\n",
1155
+ " </thead>\n",
1156
+ " <tbody>\n",
1157
+ " </tbody>\n",
1158
+ "</table>\n",
1159
+ "</div>"
1160
+ ],
1161
+ "text/plain": [
1162
+ "Empty DataFrame\n",
1163
+ "Columns: [Transaction ID, Item, Quantity, Price Per Unit, Total Spent, Payment Method, Location, Transaction Date]\n",
1164
+ "Index: []"
1165
+ ]
1166
+ },
1167
+ "execution_count": 43,
1168
+ "metadata": {},
1169
+ "output_type": "execute_result"
1170
+ }
1171
+ ],
1172
+ "source": [
1173
+ "df[df[\"Transaction ID\"].duplicated(keep=False)].sort_values(\"Transaction ID\").head(20)"
1174
+ ]
1175
+ },
1176
+ {
1177
+ "cell_type": "code",
1178
+ "execution_count": 44,
1179
+ "metadata": {},
1180
+ "outputs": [
1181
+ {
1182
+ "data": {
1183
+ "text/html": [
1184
+ "<div>\n",
1185
+ "<style scoped>\n",
1186
+ " .dataframe tbody tr th:only-of-type {\n",
1187
+ " vertical-align: middle;\n",
1188
+ " }\n",
1189
+ "\n",
1190
+ " .dataframe tbody tr th {\n",
1191
+ " vertical-align: top;\n",
1192
+ " }\n",
1193
+ "\n",
1194
+ " .dataframe thead th {\n",
1195
+ " text-align: right;\n",
1196
+ " }\n",
1197
+ "</style>\n",
1198
+ "<table border=\"1\" class=\"dataframe\">\n",
1199
+ " <thead>\n",
1200
+ " <tr style=\"text-align: right;\">\n",
1201
+ " <th></th>\n",
1202
+ " <th>Quantity</th>\n",
1203
+ " <th>Price Per Unit</th>\n",
1204
+ " <th>Total Spent</th>\n",
1205
+ " </tr>\n",
1206
+ " </thead>\n",
1207
+ " <tbody>\n",
1208
+ " <tr>\n",
1209
+ " <th>count</th>\n",
1210
+ " <td>9540.000000</td>\n",
1211
+ " <td>9540.000000</td>\n",
1212
+ " <td>9540.000000</td>\n",
1213
+ " </tr>\n",
1214
+ " <tr>\n",
1215
+ " <th>mean</th>\n",
1216
+ " <td>3.024109</td>\n",
1217
+ " <td>2.952673</td>\n",
1218
+ " <td>8.924109</td>\n",
1219
+ " </tr>\n",
1220
+ " <tr>\n",
1221
+ " <th>std</th>\n",
1222
+ " <td>1.384186</td>\n",
1223
+ " <td>1.243449</td>\n",
1224
+ " <td>5.997956</td>\n",
1225
+ " </tr>\n",
1226
+ " <tr>\n",
1227
+ " <th>min</th>\n",
1228
+ " <td>1.000000</td>\n",
1229
+ " <td>1.000000</td>\n",
1230
+ " <td>1.000000</td>\n",
1231
+ " </tr>\n",
1232
+ " <tr>\n",
1233
+ " <th>25%</th>\n",
1234
+ " <td>2.000000</td>\n",
1235
+ " <td>2.000000</td>\n",
1236
+ " <td>4.000000</td>\n",
1237
+ " </tr>\n",
1238
+ " <tr>\n",
1239
+ " <th>50%</th>\n",
1240
+ " <td>3.000000</td>\n",
1241
+ " <td>3.000000</td>\n",
1242
+ " <td>8.000000</td>\n",
1243
+ " </tr>\n",
1244
+ " <tr>\n",
1245
+ " <th>75%</th>\n",
1246
+ " <td>4.000000</td>\n",
1247
+ " <td>4.000000</td>\n",
1248
+ " <td>12.000000</td>\n",
1249
+ " </tr>\n",
1250
+ " <tr>\n",
1251
+ " <th>max</th>\n",
1252
+ " <td>5.000000</td>\n",
1253
+ " <td>5.000000</td>\n",
1254
+ " <td>25.000000</td>\n",
1255
+ " </tr>\n",
1256
+ " </tbody>\n",
1257
+ "</table>\n",
1258
+ "</div>"
1259
+ ],
1260
+ "text/plain": [
1261
+ " Quantity Price Per Unit Total Spent\n",
1262
+ "count 9540.000000 9540.000000 9540.000000\n",
1263
+ "mean 3.024109 2.952673 8.924109\n",
1264
+ "std 1.384186 1.243449 5.997956\n",
1265
+ "min 1.000000 1.000000 1.000000\n",
1266
+ "25% 2.000000 2.000000 4.000000\n",
1267
+ "50% 3.000000 3.000000 8.000000\n",
1268
+ "75% 4.000000 4.000000 12.000000\n",
1269
+ "max 5.000000 5.000000 25.000000"
1270
+ ]
1271
+ },
1272
+ "execution_count": 44,
1273
+ "metadata": {},
1274
+ "output_type": "execute_result"
1275
+ }
1276
+ ],
1277
+ "source": [
1278
+ "df[[\"Quantity\", \"Price Per Unit\", \"Total Spent\"]].describe()"
1279
+ ]
1280
+ },
1281
+ {
1282
+ "cell_type": "code",
1283
+ "execution_count": 45,
1284
+ "metadata": {},
1285
+ "outputs": [
1286
+ {
1287
+ "name": "stdout",
1288
+ "output_type": "stream",
1289
+ "text": [
1290
+ "Quantity:\n",
1291
+ "Negative values: 0\n",
1292
+ "Zero values: 0\n",
1293
+ "\n",
1294
+ "Price Per Unit:\n",
1295
+ "Negative values: 0\n",
1296
+ "Zero values: 0\n",
1297
+ "\n",
1298
+ "Total Spent:\n",
1299
+ "Negative values: 0\n",
1300
+ "Zero values: 0\n",
1301
+ "\n"
1302
+ ]
1303
+ }
1304
+ ],
1305
+ "source": [
1306
+ "for col in [\"Quantity\", \"Price Per Unit\", \"Total Spent\"]:\n",
1307
+ " print(f\"{col}:\")\n",
1308
+ " print(\"Negative values:\", (df[col] < 0).sum())\n",
1309
+ " print(\"Zero values:\", (df[col] == 0).sum())\n",
1310
+ " print()"
1311
+ ]
1312
+ },
1313
+ {
1314
+ "cell_type": "code",
1315
+ "execution_count": 46,
1316
+ "metadata": {},
1317
+ "outputs": [
1318
+ {
1319
+ "name": "stdout",
1320
+ "output_type": "stream",
1321
+ "text": [
1322
+ "\n",
1323
+ "Quantity:\n",
1324
+ "[np.float64(1.0), np.float64(2.0), np.float64(3.0), np.float64(4.0), np.float64(5.0)]\n",
1325
+ "\n",
1326
+ "Price Per Unit:\n",
1327
+ "[np.float64(1.0), np.float64(1.5), np.float64(2.0), np.float64(3.0), np.float64(4.0), np.float64(5.0)]\n",
1328
+ "\n",
1329
+ "Total Spent:\n",
1330
+ "[np.float64(1.0), np.float64(1.5), np.float64(2.0), np.float64(3.0), np.float64(4.0), np.float64(4.5), np.float64(5.0), np.float64(6.0), np.float64(7.5), np.float64(8.0), np.float64(9.0), np.float64(10.0), np.float64(12.0), np.float64(15.0), np.float64(16.0), np.float64(20.0), np.float64(25.0)]\n"
1331
+ ]
1332
+ }
1333
+ ],
1334
+ "source": [
1335
+ "for col in [\"Quantity\", \"Price Per Unit\", \"Total Spent\"]:\n",
1336
+ " print(f\"\\n{col}:\")\n",
1337
+ " print(sorted(df[col].dropna().unique()))"
1338
+ ]
1339
+ },
1340
+ {
1341
+ "cell_type": "code",
1342
+ "execution_count": 47,
1343
+ "metadata": {},
1344
+ "outputs": [],
1345
+ "source": [
1346
+ "categorical_columns = [\n",
1347
+ " \"Item\",\n",
1348
+ " \"Payment Method\",\n",
1349
+ " \"Location\"\n",
1350
+ "]\n",
1351
+ "\n",
1352
+ "for col in categorical_columns:\n",
1353
+ " df[col] = df[col].str.strip()"
1354
+ ]
1355
+ },
1356
+ {
1357
+ "cell_type": "code",
1358
+ "execution_count": 48,
1359
+ "metadata": {},
1360
+ "outputs": [
1361
+ {
1362
+ "name": "stdout",
1363
+ "output_type": "stream",
1364
+ "text": [
1365
+ "\n",
1366
+ "--- Item ---\n",
1367
+ "<StringArray>\n",
1368
+ "['Coffee', 'Cake', 'Cookie', 'Salad', 'Smoothie', 'Juice', 'Sandwich', 'Tea']\n",
1369
+ "Length: 8, dtype: str\n",
1370
+ "\n",
1371
+ "--- Payment Method ---\n",
1372
+ "<StringArray>\n",
1373
+ "['Credit Card', 'Cash', 'Digital Wallet']\n",
1374
+ "Length: 3, dtype: str\n",
1375
+ "\n",
1376
+ "--- Location ---\n",
1377
+ "<StringArray>\n",
1378
+ "['Takeaway', 'In-store', 'Unknown']\n",
1379
+ "Length: 3, dtype: str\n"
1380
+ ]
1381
+ }
1382
+ ],
1383
+ "source": [
1384
+ "for col in categorical_columns:\n",
1385
+ " print(f\"\\n--- {col} ---\")\n",
1386
+ " print(df[col].unique())"
1387
+ ]
1388
+ },
1389
+ {
1390
+ "cell_type": "code",
1391
+ "execution_count": 49,
1392
+ "metadata": {},
1393
+ "outputs": [
1394
+ {
1395
+ "name": "stdout",
1396
+ "output_type": "stream",
1397
+ "text": [
1398
+ "\n",
1399
+ "Item value counts:\n",
1400
+ "Item\n",
1401
+ "Juice 2051\n",
1402
+ "Coffee 1123\n",
1403
+ "Salad 1099\n",
1404
+ "Cake 1082\n",
1405
+ "Sandwich 1075\n",
1406
+ "Smoothie 1048\n",
1407
+ "Cookie 1035\n",
1408
+ "Tea 1027\n",
1409
+ "Name: count, dtype: int64\n",
1410
+ "\n",
1411
+ "Payment Method value counts:\n",
1412
+ "Payment Method\n",
1413
+ "Digital Wallet 5212\n",
1414
+ "Credit Card 2170\n",
1415
+ "Cash 2158\n",
1416
+ "Name: count, dtype: int64\n",
1417
+ "\n",
1418
+ "Location value counts:\n",
1419
+ "Location\n",
1420
+ "Unknown 3779\n",
1421
+ "Takeaway 2889\n",
1422
+ "In-store 2872\n",
1423
+ "Name: count, dtype: int64\n"
1424
+ ]
1425
+ }
1426
+ ],
1427
+ "source": [
1428
+ "for col in categorical_columns:\n",
1429
+ " print(f\"\\n{col} value counts:\")\n",
1430
+ " print(df[col].value_counts())"
1431
+ ]
1432
+ },
1433
+ {
1434
+ "cell_type": "markdown",
1435
+ "metadata": {},
1436
+ "source": [
1437
+ "# Final Dataset Quality Check"
1438
+ ]
1439
+ },
1440
+ {
1441
+ "cell_type": "code",
1442
+ "execution_count": 50,
1443
+ "metadata": {},
1444
+ "outputs": [
1445
+ {
1446
+ "data": {
1447
+ "text/plain": [
1448
+ "Transaction ID 0\n",
1449
+ "Item 0\n",
1450
+ "Quantity 0\n",
1451
+ "Price Per Unit 0\n",
1452
+ "Total Spent 0\n",
1453
+ "Payment Method 0\n",
1454
+ "Location 0\n",
1455
+ "Transaction Date 0\n",
1456
+ "dtype: int64"
1457
+ ]
1458
+ },
1459
+ "execution_count": 50,
1460
+ "metadata": {},
1461
+ "output_type": "execute_result"
1462
+ }
1463
+ ],
1464
+ "source": [
1465
+ "df.isnull().sum()"
1466
+ ]
1467
+ },
1468
+ {
1469
+ "cell_type": "code",
1470
+ "execution_count": 51,
1471
+ "metadata": {},
1472
+ "outputs": [
1473
+ {
1474
+ "data": {
1475
+ "text/plain": [
1476
+ "Transaction ID str\n",
1477
+ "Item str\n",
1478
+ "Quantity float64\n",
1479
+ "Price Per Unit float64\n",
1480
+ "Total Spent float64\n",
1481
+ "Payment Method str\n",
1482
+ "Location str\n",
1483
+ "Transaction Date datetime64[us]\n",
1484
+ "dtype: object"
1485
+ ]
1486
+ },
1487
+ "execution_count": 51,
1488
+ "metadata": {},
1489
+ "output_type": "execute_result"
1490
+ }
1491
+ ],
1492
+ "source": [
1493
+ "df.dtypes"
1494
+ ]
1495
+ },
1496
+ {
1497
+ "cell_type": "code",
1498
+ "execution_count": 52,
1499
+ "metadata": {},
1500
+ "outputs": [
1501
+ {
1502
+ "name": "stdout",
1503
+ "output_type": "stream",
1504
+ "text": [
1505
+ "Duplicate rows: 0\n",
1506
+ "Duplicate Transaction IDs: 0\n"
1507
+ ]
1508
+ }
1509
+ ],
1510
+ "source": [
1511
+ "print(\"Duplicate rows:\", df.duplicated().sum())\n",
1512
+ "print(\"Duplicate Transaction IDs:\", df[\"Transaction ID\"].duplicated().sum())"
1513
+ ]
1514
+ },
1515
+ {
1516
+ "cell_type": "code",
1517
+ "execution_count": 53,
1518
+ "metadata": {},
1519
+ "outputs": [
1520
+ {
1521
+ "name": "stdout",
1522
+ "output_type": "stream",
1523
+ "text": [
1524
+ "Total Spent mismatches: 696\n"
1525
+ ]
1526
+ }
1527
+ ],
1528
+ "source": [
1529
+ "calculated_total = df[\"Quantity\"] * df[\"Price Per Unit\"]\n",
1530
+ "\n",
1531
+ "total_mismatch = (\n",
1532
+ " (df[\"Total Spent\"] - calculated_total).abs() > 0.001\n",
1533
+ ")\n",
1534
+ "\n",
1535
+ "print(\"Total Spent mismatches:\", total_mismatch.sum())"
1536
+ ]
1537
+ },
1538
+ {
1539
+ "cell_type": "code",
1540
+ "execution_count": 54,
1541
+ "metadata": {},
1542
+ "outputs": [],
1543
+ "source": [
1544
+ "df[\"Total Spent\"] = df[\"Quantity\"] * df[\"Price Per Unit\"]"
1545
+ ]
1546
+ },
1547
+ {
1548
+ "cell_type": "code",
1549
+ "execution_count": 55,
1550
+ "metadata": {},
1551
+ "outputs": [
1552
+ {
1553
+ "name": "stdout",
1554
+ "output_type": "stream",
1555
+ "text": [
1556
+ "Total Spent mismatches: 0\n"
1557
+ ]
1558
+ }
1559
+ ],
1560
+ "source": [
1561
+ "calculated_total = df[\"Quantity\"] * df[\"Price Per Unit\"]\n",
1562
+ "\n",
1563
+ "total_mismatch = (\n",
1564
+ " (df[\"Total Spent\"] - calculated_total).abs() > 0.001\n",
1565
+ ")\n",
1566
+ "\n",
1567
+ "print(\"Total Spent mismatches:\", total_mismatch.sum())"
1568
+ ]
1569
+ },
1570
+ {
1571
+ "cell_type": "code",
1572
+ "execution_count": 56,
1573
+ "metadata": {},
1574
+ "outputs": [
1575
+ {
1576
+ "name": "stdout",
1577
+ "output_type": "stream",
1578
+ "text": [
1579
+ "Dataset Shape: (9540, 8)\n",
1580
+ "\n",
1581
+ "Missing Values:\n",
1582
+ "Transaction ID 0\n",
1583
+ "Item 0\n",
1584
+ "Quantity 0\n",
1585
+ "Price Per Unit 0\n",
1586
+ "Total Spent 0\n",
1587
+ "Payment Method 0\n",
1588
+ "Location 0\n",
1589
+ "Transaction Date 0\n",
1590
+ "dtype: int64\n",
1591
+ "\n",
1592
+ "Duplicate Rows: 0\n",
1593
+ "Duplicate Transaction IDs: 0\n",
1594
+ "\n",
1595
+ "Data Types:\n",
1596
+ "Transaction ID str\n",
1597
+ "Item str\n",
1598
+ "Quantity float64\n",
1599
+ "Price Per Unit float64\n",
1600
+ "Total Spent float64\n",
1601
+ "Payment Method str\n",
1602
+ "Location str\n",
1603
+ "Transaction Date datetime64[us]\n",
1604
+ "dtype: object\n",
1605
+ "\n",
1606
+ "Total Spent Mismatches:\n",
1607
+ "0\n"
1608
+ ]
1609
+ }
1610
+ ],
1611
+ "source": [
1612
+ "print(\"Dataset Shape:\", df.shape)\n",
1613
+ "print(\"\\nMissing Values:\")\n",
1614
+ "print(df.isnull().sum())\n",
1615
+ "\n",
1616
+ "print(\"\\nDuplicate Rows:\", df.duplicated().sum())\n",
1617
+ "print(\"Duplicate Transaction IDs:\", df[\"Transaction ID\"].duplicated().sum())\n",
1618
+ "\n",
1619
+ "print(\"\\nData Types:\")\n",
1620
+ "print(df.dtypes)\n",
1621
+ "\n",
1622
+ "print(\"\\nTotal Spent Mismatches:\")\n",
1623
+ "\n",
1624
+ "calculated_total = df[\"Quantity\"] * df[\"Price Per Unit\"]\n",
1625
+ "\n",
1626
+ "total_mismatch = (\n",
1627
+ " (df[\"Total Spent\"] - calculated_total).abs() > 0.001\n",
1628
+ ")\n",
1629
+ "\n",
1630
+ "print(total_mismatch.sum())"
1631
+ ]
1632
+ },
1633
+ {
1634
+ "cell_type": "code",
1635
+ "execution_count": 57,
1636
+ "metadata": {},
1637
+ "outputs": [
1638
+ {
1639
+ "data": {
1640
+ "text/html": [
1641
+ "<div>\n",
1642
+ "<style scoped>\n",
1643
+ " .dataframe tbody tr th:only-of-type {\n",
1644
+ " vertical-align: middle;\n",
1645
+ " }\n",
1646
+ "\n",
1647
+ " .dataframe tbody tr th {\n",
1648
+ " vertical-align: top;\n",
1649
+ " }\n",
1650
+ "\n",
1651
+ " .dataframe thead th {\n",
1652
+ " text-align: right;\n",
1653
+ " }\n",
1654
+ "</style>\n",
1655
+ "<table border=\"1\" class=\"dataframe\">\n",
1656
+ " <thead>\n",
1657
+ " <tr style=\"text-align: right;\">\n",
1658
+ " <th></th>\n",
1659
+ " <th>Transaction ID</th>\n",
1660
+ " <th>Item</th>\n",
1661
+ " <th>Quantity</th>\n",
1662
+ " <th>Price Per Unit</th>\n",
1663
+ " <th>Total Spent</th>\n",
1664
+ " <th>Payment Method</th>\n",
1665
+ " <th>Location</th>\n",
1666
+ " <th>Transaction Date</th>\n",
1667
+ " </tr>\n",
1668
+ " </thead>\n",
1669
+ " <tbody>\n",
1670
+ " <tr>\n",
1671
+ " <th>0</th>\n",
1672
+ " <td>TXN_1961373</td>\n",
1673
+ " <td>Coffee</td>\n",
1674
+ " <td>2.0</td>\n",
1675
+ " <td>2.0</td>\n",
1676
+ " <td>4.0</td>\n",
1677
+ " <td>Credit Card</td>\n",
1678
+ " <td>Takeaway</td>\n",
1679
+ " <td>2023-09-08</td>\n",
1680
+ " </tr>\n",
1681
+ " <tr>\n",
1682
+ " <th>1</th>\n",
1683
+ " <td>TXN_4977031</td>\n",
1684
+ " <td>Cake</td>\n",
1685
+ " <td>4.0</td>\n",
1686
+ " <td>3.0</td>\n",
1687
+ " <td>12.0</td>\n",
1688
+ " <td>Cash</td>\n",
1689
+ " <td>In-store</td>\n",
1690
+ " <td>2023-05-16</td>\n",
1691
+ " </tr>\n",
1692
+ " <tr>\n",
1693
+ " <th>2</th>\n",
1694
+ " <td>TXN_4271903</td>\n",
1695
+ " <td>Cookie</td>\n",
1696
+ " <td>4.0</td>\n",
1697
+ " <td>1.0</td>\n",
1698
+ " <td>4.0</td>\n",
1699
+ " <td>Credit Card</td>\n",
1700
+ " <td>In-store</td>\n",
1701
+ " <td>2023-07-19</td>\n",
1702
+ " </tr>\n",
1703
+ " <tr>\n",
1704
+ " <th>3</th>\n",
1705
+ " <td>TXN_7034554</td>\n",
1706
+ " <td>Salad</td>\n",
1707
+ " <td>2.0</td>\n",
1708
+ " <td>5.0</td>\n",
1709
+ " <td>10.0</td>\n",
1710
+ " <td>Digital Wallet</td>\n",
1711
+ " <td>Unknown</td>\n",
1712
+ " <td>2023-04-27</td>\n",
1713
+ " </tr>\n",
1714
+ " <tr>\n",
1715
+ " <th>4</th>\n",
1716
+ " <td>TXN_3160411</td>\n",
1717
+ " <td>Coffee</td>\n",
1718
+ " <td>2.0</td>\n",
1719
+ " <td>2.0</td>\n",
1720
+ " <td>4.0</td>\n",
1721
+ " <td>Digital Wallet</td>\n",
1722
+ " <td>In-store</td>\n",
1723
+ " <td>2023-06-11</td>\n",
1724
+ " </tr>\n",
1725
+ " <tr>\n",
1726
+ " <th>5</th>\n",
1727
+ " <td>TXN_2602893</td>\n",
1728
+ " <td>Smoothie</td>\n",
1729
+ " <td>5.0</td>\n",
1730
+ " <td>4.0</td>\n",
1731
+ " <td>20.0</td>\n",
1732
+ " <td>Credit Card</td>\n",
1733
+ " <td>Unknown</td>\n",
1734
+ " <td>2023-03-31</td>\n",
1735
+ " </tr>\n",
1736
+ " <tr>\n",
1737
+ " <th>6</th>\n",
1738
+ " <td>TXN_4433211</td>\n",
1739
+ " <td>Juice</td>\n",
1740
+ " <td>3.0</td>\n",
1741
+ " <td>3.0</td>\n",
1742
+ " <td>9.0</td>\n",
1743
+ " <td>Digital Wallet</td>\n",
1744
+ " <td>Takeaway</td>\n",
1745
+ " <td>2023-10-06</td>\n",
1746
+ " </tr>\n",
1747
+ " <tr>\n",
1748
+ " <th>7</th>\n",
1749
+ " <td>TXN_6699534</td>\n",
1750
+ " <td>Sandwich</td>\n",
1751
+ " <td>4.0</td>\n",
1752
+ " <td>4.0</td>\n",
1753
+ " <td>16.0</td>\n",
1754
+ " <td>Cash</td>\n",
1755
+ " <td>Unknown</td>\n",
1756
+ " <td>2023-10-28</td>\n",
1757
+ " </tr>\n",
1758
+ " <tr>\n",
1759
+ " <th>8</th>\n",
1760
+ " <td>TXN_4717867</td>\n",
1761
+ " <td>Juice</td>\n",
1762
+ " <td>5.0</td>\n",
1763
+ " <td>3.0</td>\n",
1764
+ " <td>15.0</td>\n",
1765
+ " <td>Digital Wallet</td>\n",
1766
+ " <td>Takeaway</td>\n",
1767
+ " <td>2023-07-28</td>\n",
1768
+ " </tr>\n",
1769
+ " <tr>\n",
1770
+ " <th>9</th>\n",
1771
+ " <td>TXN_2064365</td>\n",
1772
+ " <td>Sandwich</td>\n",
1773
+ " <td>5.0</td>\n",
1774
+ " <td>4.0</td>\n",
1775
+ " <td>20.0</td>\n",
1776
+ " <td>Digital Wallet</td>\n",
1777
+ " <td>In-store</td>\n",
1778
+ " <td>2023-12-31</td>\n",
1779
+ " </tr>\n",
1780
+ " </tbody>\n",
1781
+ "</table>\n",
1782
+ "</div>"
1783
+ ],
1784
+ "text/plain": [
1785
+ " Transaction ID Item Quantity Price Per Unit Total Spent \\\n",
1786
+ "0 TXN_1961373 Coffee 2.0 2.0 4.0 \n",
1787
+ "1 TXN_4977031 Cake 4.0 3.0 12.0 \n",
1788
+ "2 TXN_4271903 Cookie 4.0 1.0 4.0 \n",
1789
+ "3 TXN_7034554 Salad 2.0 5.0 10.0 \n",
1790
+ "4 TXN_3160411 Coffee 2.0 2.0 4.0 \n",
1791
+ "5 TXN_2602893 Smoothie 5.0 4.0 20.0 \n",
1792
+ "6 TXN_4433211 Juice 3.0 3.0 9.0 \n",
1793
+ "7 TXN_6699534 Sandwich 4.0 4.0 16.0 \n",
1794
+ "8 TXN_4717867 Juice 5.0 3.0 15.0 \n",
1795
+ "9 TXN_2064365 Sandwich 5.0 4.0 20.0 \n",
1796
+ "\n",
1797
+ " Payment Method Location Transaction Date \n",
1798
+ "0 Credit Card Takeaway 2023-09-08 \n",
1799
+ "1 Cash In-store 2023-05-16 \n",
1800
+ "2 Credit Card In-store 2023-07-19 \n",
1801
+ "3 Digital Wallet Unknown 2023-04-27 \n",
1802
+ "4 Digital Wallet In-store 2023-06-11 \n",
1803
+ "5 Credit Card Unknown 2023-03-31 \n",
1804
+ "6 Digital Wallet Takeaway 2023-10-06 \n",
1805
+ "7 Cash Unknown 2023-10-28 \n",
1806
+ "8 Digital Wallet Takeaway 2023-07-28 \n",
1807
+ "9 Digital Wallet In-store 2023-12-31 "
1808
+ ]
1809
+ },
1810
+ "execution_count": 57,
1811
+ "metadata": {},
1812
+ "output_type": "execute_result"
1813
+ }
1814
+ ],
1815
+ "source": [
1816
+ "df.head(10)"
1817
+ ]
1818
+ },
1819
+ {
1820
+ "cell_type": "code",
1821
+ "execution_count": 58,
1822
+ "metadata": {},
1823
+ "outputs": [
1824
+ {
1825
+ "data": {
1826
+ "text/html": [
1827
+ "<div>\n",
1828
+ "<style scoped>\n",
1829
+ " .dataframe tbody tr th:only-of-type {\n",
1830
+ " vertical-align: middle;\n",
1831
+ " }\n",
1832
+ "\n",
1833
+ " .dataframe tbody tr th {\n",
1834
+ " vertical-align: top;\n",
1835
+ " }\n",
1836
+ "\n",
1837
+ " .dataframe thead th {\n",
1838
+ " text-align: right;\n",
1839
+ " }\n",
1840
+ "</style>\n",
1841
+ "<table border=\"1\" class=\"dataframe\">\n",
1842
+ " <thead>\n",
1843
+ " <tr style=\"text-align: right;\">\n",
1844
+ " <th></th>\n",
1845
+ " <th>Transaction ID</th>\n",
1846
+ " <th>Item</th>\n",
1847
+ " <th>Quantity</th>\n",
1848
+ " <th>Price Per Unit</th>\n",
1849
+ " <th>Total Spent</th>\n",
1850
+ " <th>Payment Method</th>\n",
1851
+ " <th>Location</th>\n",
1852
+ " <th>Transaction Date</th>\n",
1853
+ " </tr>\n",
1854
+ " </thead>\n",
1855
+ " <tbody>\n",
1856
+ " <tr>\n",
1857
+ " <th>9990</th>\n",
1858
+ " <td>TXN_1538510</td>\n",
1859
+ " <td>Coffee</td>\n",
1860
+ " <td>5.0</td>\n",
1861
+ " <td>2.0</td>\n",
1862
+ " <td>10.0</td>\n",
1863
+ " <td>Digital Wallet</td>\n",
1864
+ " <td>Unknown</td>\n",
1865
+ " <td>2023-05-22</td>\n",
1866
+ " </tr>\n",
1867
+ " <tr>\n",
1868
+ " <th>9991</th>\n",
1869
+ " <td>TXN_3897619</td>\n",
1870
+ " <td>Sandwich</td>\n",
1871
+ " <td>3.0</td>\n",
1872
+ " <td>4.0</td>\n",
1873
+ " <td>12.0</td>\n",
1874
+ " <td>Cash</td>\n",
1875
+ " <td>Takeaway</td>\n",
1876
+ " <td>2023-02-24</td>\n",
1877
+ " </tr>\n",
1878
+ " <tr>\n",
1879
+ " <th>9992</th>\n",
1880
+ " <td>TXN_2739140</td>\n",
1881
+ " <td>Smoothie</td>\n",
1882
+ " <td>4.0</td>\n",
1883
+ " <td>4.0</td>\n",
1884
+ " <td>16.0</td>\n",
1885
+ " <td>Digital Wallet</td>\n",
1886
+ " <td>In-store</td>\n",
1887
+ " <td>2023-07-05</td>\n",
1888
+ " </tr>\n",
1889
+ " <tr>\n",
1890
+ " <th>9993</th>\n",
1891
+ " <td>TXN_4766549</td>\n",
1892
+ " <td>Smoothie</td>\n",
1893
+ " <td>2.0</td>\n",
1894
+ " <td>4.0</td>\n",
1895
+ " <td>8.0</td>\n",
1896
+ " <td>Cash</td>\n",
1897
+ " <td>Unknown</td>\n",
1898
+ " <td>2023-10-20</td>\n",
1899
+ " </tr>\n",
1900
+ " <tr>\n",
1901
+ " <th>9994</th>\n",
1902
+ " <td>TXN_7851634</td>\n",
1903
+ " <td>Juice</td>\n",
1904
+ " <td>4.0</td>\n",
1905
+ " <td>4.0</td>\n",
1906
+ " <td>16.0</td>\n",
1907
+ " <td>Digital Wallet</td>\n",
1908
+ " <td>Unknown</td>\n",
1909
+ " <td>2023-01-08</td>\n",
1910
+ " </tr>\n",
1911
+ " <tr>\n",
1912
+ " <th>9995</th>\n",
1913
+ " <td>TXN_7672686</td>\n",
1914
+ " <td>Coffee</td>\n",
1915
+ " <td>2.0</td>\n",
1916
+ " <td>2.0</td>\n",
1917
+ " <td>4.0</td>\n",
1918
+ " <td>Digital Wallet</td>\n",
1919
+ " <td>Unknown</td>\n",
1920
+ " <td>2023-08-30</td>\n",
1921
+ " </tr>\n",
1922
+ " <tr>\n",
1923
+ " <th>9996</th>\n",
1924
+ " <td>TXN_9659401</td>\n",
1925
+ " <td>Juice</td>\n",
1926
+ " <td>3.0</td>\n",
1927
+ " <td>3.0</td>\n",
1928
+ " <td>9.0</td>\n",
1929
+ " <td>Digital Wallet</td>\n",
1930
+ " <td>Unknown</td>\n",
1931
+ " <td>2023-06-02</td>\n",
1932
+ " </tr>\n",
1933
+ " <tr>\n",
1934
+ " <th>9997</th>\n",
1935
+ " <td>TXN_5255387</td>\n",
1936
+ " <td>Coffee</td>\n",
1937
+ " <td>4.0</td>\n",
1938
+ " <td>2.0</td>\n",
1939
+ " <td>8.0</td>\n",
1940
+ " <td>Digital Wallet</td>\n",
1941
+ " <td>Unknown</td>\n",
1942
+ " <td>2023-03-02</td>\n",
1943
+ " </tr>\n",
1944
+ " <tr>\n",
1945
+ " <th>9998</th>\n",
1946
+ " <td>TXN_7695629</td>\n",
1947
+ " <td>Cookie</td>\n",
1948
+ " <td>3.0</td>\n",
1949
+ " <td>3.0</td>\n",
1950
+ " <td>9.0</td>\n",
1951
+ " <td>Digital Wallet</td>\n",
1952
+ " <td>Unknown</td>\n",
1953
+ " <td>2023-12-02</td>\n",
1954
+ " </tr>\n",
1955
+ " <tr>\n",
1956
+ " <th>9999</th>\n",
1957
+ " <td>TXN_6170729</td>\n",
1958
+ " <td>Sandwich</td>\n",
1959
+ " <td>3.0</td>\n",
1960
+ " <td>4.0</td>\n",
1961
+ " <td>12.0</td>\n",
1962
+ " <td>Cash</td>\n",
1963
+ " <td>In-store</td>\n",
1964
+ " <td>2023-11-07</td>\n",
1965
+ " </tr>\n",
1966
+ " </tbody>\n",
1967
+ "</table>\n",
1968
+ "</div>"
1969
+ ],
1970
+ "text/plain": [
1971
+ " Transaction ID Item Quantity Price Per Unit Total Spent \\\n",
1972
+ "9990 TXN_1538510 Coffee 5.0 2.0 10.0 \n",
1973
+ "9991 TXN_3897619 Sandwich 3.0 4.0 12.0 \n",
1974
+ "9992 TXN_2739140 Smoothie 4.0 4.0 16.0 \n",
1975
+ "9993 TXN_4766549 Smoothie 2.0 4.0 8.0 \n",
1976
+ "9994 TXN_7851634 Juice 4.0 4.0 16.0 \n",
1977
+ "9995 TXN_7672686 Coffee 2.0 2.0 4.0 \n",
1978
+ "9996 TXN_9659401 Juice 3.0 3.0 9.0 \n",
1979
+ "9997 TXN_5255387 Coffee 4.0 2.0 8.0 \n",
1980
+ "9998 TXN_7695629 Cookie 3.0 3.0 9.0 \n",
1981
+ "9999 TXN_6170729 Sandwich 3.0 4.0 12.0 \n",
1982
+ "\n",
1983
+ " Payment Method Location Transaction Date \n",
1984
+ "9990 Digital Wallet Unknown 2023-05-22 \n",
1985
+ "9991 Cash Takeaway 2023-02-24 \n",
1986
+ "9992 Digital Wallet In-store 2023-07-05 \n",
1987
+ "9993 Cash Unknown 2023-10-20 \n",
1988
+ "9994 Digital Wallet Unknown 2023-01-08 \n",
1989
+ "9995 Digital Wallet Unknown 2023-08-30 \n",
1990
+ "9996 Digital Wallet Unknown 2023-06-02 \n",
1991
+ "9997 Digital Wallet Unknown 2023-03-02 \n",
1992
+ "9998 Digital Wallet Unknown 2023-12-02 \n",
1993
+ "9999 Cash In-store 2023-11-07 "
1994
+ ]
1995
+ },
1996
+ "execution_count": 58,
1997
+ "metadata": {},
1998
+ "output_type": "execute_result"
1999
+ }
2000
+ ],
2001
+ "source": [
2002
+ "df.tail(10)"
2003
+ ]
2004
+ },
2005
+ {
2006
+ "cell_type": "code",
2007
+ "execution_count": 59,
2008
+ "metadata": {},
2009
+ "outputs": [
2010
+ {
2011
+ "data": {
2012
+ "text/plain": [
2013
+ "['Transaction ID',\n",
2014
+ " 'Item',\n",
2015
+ " 'Quantity',\n",
2016
+ " 'Price Per Unit',\n",
2017
+ " 'Total Spent',\n",
2018
+ " 'Payment Method',\n",
2019
+ " 'Location',\n",
2020
+ " 'Transaction Date']"
2021
+ ]
2022
+ },
2023
+ "execution_count": 59,
2024
+ "metadata": {},
2025
+ "output_type": "execute_result"
2026
+ }
2027
+ ],
2028
+ "source": [
2029
+ "df.columns.tolist()"
2030
+ ]
2031
+ },
2032
+ {
2033
+ "cell_type": "code",
2034
+ "execution_count": 60,
2035
+ "metadata": {},
2036
+ "outputs": [],
2037
+ "source": [
2038
+ "df.to_csv(\"cleaned_cafe_sales.csv\", index=False)"
2039
+ ]
2040
+ },
2041
+ {
2042
+ "cell_type": "code",
2043
+ "execution_count": 61,
2044
+ "metadata": {},
2045
+ "outputs": [
2046
+ {
2047
+ "name": "stdout",
2048
+ "output_type": "stream",
2049
+ "text": [
2050
+ "File exists: True\n"
2051
+ ]
2052
+ }
2053
+ ],
2054
+ "source": [
2055
+ "import os\n",
2056
+ "\n",
2057
+ "print(\"File exists:\", os.path.exists(\"cleaned_cafe_sales.csv\"))"
2058
+ ]
2059
+ },
2060
+ {
2061
+ "cell_type": "markdown",
2062
+ "metadata": {},
2063
+ "source": [
2064
+ "# Confirmation to see whether our cleaned csv file is loading or not"
2065
+ ]
2066
+ },
2067
+ {
2068
+ "cell_type": "code",
2069
+ "execution_count": 62,
2070
+ "metadata": {},
2071
+ "outputs": [
2072
+ {
2073
+ "name": "stdout",
2074
+ "output_type": "stream",
2075
+ "text": [
2076
+ "Shape: (9540, 8)\n",
2077
+ "\n",
2078
+ "Missing values:\n",
2079
+ "Transaction ID 0\n",
2080
+ "Item 0\n",
2081
+ "Quantity 0\n",
2082
+ "Price Per Unit 0\n",
2083
+ "Total Spent 0\n",
2084
+ "Payment Method 0\n",
2085
+ "Location 0\n",
2086
+ "Transaction Date 0\n",
2087
+ "dtype: int64\n"
2088
+ ]
2089
+ }
2090
+ ],
2091
+ "source": [
2092
+ "cleaned_df = pd.read_csv(\"cleaned_cafe_sales.csv\")\n",
2093
+ "\n",
2094
+ "print(\"Shape:\", cleaned_df.shape)\n",
2095
+ "print(\"\\nMissing values:\")\n",
2096
+ "print(cleaned_df.isnull().sum())"
2097
+ ]
2098
+ },
2099
+ {
2100
+ "cell_type": "code",
2101
+ "execution_count": null,
2102
+ "metadata": {},
2103
+ "outputs": [],
2104
+ "source": []
2105
+ }
2106
+ ],
2107
+ "metadata": {
2108
+ "kernelspec": {
2109
+ "display_name": "venv",
2110
+ "language": "python",
2111
+ "name": "python3"
2112
+ },
2113
+ "language_info": {
2114
+ "codemirror_mode": {
2115
+ "name": "ipython",
2116
+ "version": 3
2117
+ },
2118
+ "file_extension": ".py",
2119
+ "mimetype": "text/x-python",
2120
+ "name": "python",
2121
+ "nbconvert_exporter": "python",
2122
+ "pygments_lexer": "ipython3",
2123
+ "version": "3.14.7"
2124
+ }
2125
+ },
2126
+ "nbformat": 4,
2127
+ "nbformat_minor": 2
2128
+ }