File size: 11,644 Bytes
7134131
 
 
 
139b382
7134131
 
 
 
 
 
 
139b382
 
 
 
 
 
 
7134131
 
 
 
 
 
 
 
 
731a556
7134131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
731a556
139b382
 
731a556
 
139b382
 
 
 
7134131
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
139b382
731a556
7134131
 
 
139b382
7134131
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
731a556
139b382
731a556
7134131
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
731a556
7134131
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
139b382
 
 
731a556
7134131
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
139b382
 
 
 
 
 
 
 
 
 
 
 
 
7134131
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
139b382
 
 
7134131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
139b382
 
 
 
 
731a556
7134131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
 
 
 
 
731a556
 
7134131
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
139b382
 
7134131
 
 
 
 
 
 
 
731a556
7134131
 
 
731a556
7134131
731a556
7134131
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
731a556
7134131
 
 
 
 
 
 
 
 
731a556
7134131
 
 
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
731a556
7134131
 
 
 
 
 
 
 
 
 
139b382
7134131
 
 
 
 
 
 
 
 
731a556
 
 
139b382
731a556
 
 
 
 
 
 
139b382
731a556
 
 
 
139b382
731a556
 
 
 
 
 
 
139b382
731a556
 
 
 
 
 
 
139b382
731a556
 
 
 
 
 
 
 
 
 
 
 
 
139b382
731a556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7134131
 
 
 
731a556
7134131
 
 
 
 
 
 
 
 
 
 
 
 
731a556
7134131
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d77bdb7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total rows: 752\n",
      "                    Name      Number\n",
      "0                zahidur  1781133333\n",
      "2       MD Jahidul Islam  1727074508\n",
      "4         Shafiqul Islam  1716603589\n",
      "6  Mujahidor Rahamanhalo  1337103616\n",
      "8            Jahid Hasan  1766435938\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import warnings\n",
    "\n",
    "# warnings.filterwarnings(\"ignore\", category=UserWarning)\n",
    "\n",
    "file = \"df.xlsx\"\n",
    "\n",
    "df = pd.read_excel(\n",
    "    file,\n",
    "    sheet_name=None,\n",
    "    dtype=str,\n",
    "    engine=\"openpyxl\"\n",
    ")\n",
    "\n",
    "combined_df = pd.concat(df.values(), ignore_index=True)\n",
    "\n",
    "combined_df.columns = combined_df.columns.str.strip()\n",
    "df = combined_df.dropna(how=\"all\")\n",
    "\n",
    "print(\"Total rows:\", len(df))\n",
    "print(df.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "76e2e1f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.DataFrame'>\n",
      "Index: 752 entries, 0 to 1258\n",
      "Data columns (total 2 columns):\n",
      " #   Column  Non-Null Count  Dtype\n",
      "---  ------  --------------  -----\n",
      " 0   Name    751 non-null    str  \n",
      " 1   Number  752 non-null    str  \n",
      "dtypes: str(2)\n",
      "memory usage: 17.6 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3dc2adc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name       True\n",
       "Number    False\n",
       "dtype: bool"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.isnull().any()  # check for missing values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "116b9212",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Empty DataFrame\n",
      "Columns: [Name, Number]\n",
      "Index: []\n"
     ]
    }
   ],
   "source": [
    "# Filter rows where Number is null\n",
    "missing_number = df[df[\"Number\"].isna()]\n",
    "print(missing_number)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1cd12680",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.dropna(inplace=True)  # remove rows with missing values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ce33dead",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name      False\n",
       "Number    False\n",
       "dtype: bool"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.isnull().any()  # check for missing values in each column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "18faac6b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number\n",
      "6             8\n",
      "1819228188    2\n",
      "1816720138    2\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "duplicate_numbers = df[\"Number\"].value_counts()\n",
    "duplicate_numbers = duplicate_numbers[duplicate_numbers > 1]\n",
    "print(duplicate_numbers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "32d94a22",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                     Name      Number\n",
      "267                     5           6\n",
      "322                     5           6\n",
      "363                     5           6\n",
      "442                     5           6\n",
      "533                     5           6\n",
      "634                     5           6\n",
      "735                     5           6\n",
      "828                     5           6\n",
      "1101  Anisur Rahman Sinha  1819228188\n",
      "1136  Anisur Rahman Sinha  1819228188\n",
      "1170   A. Salam Choudhury  1816720138\n",
      "1198    Shaheer Choudhury  1816720138\n"
     ]
    }
   ],
   "source": [
    "duplicates = df[df.duplicated(subset=[\"Number\"], keep=False)]\n",
    "print(duplicates.head(50))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0f5af544",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Before: 751\n",
      "After : 742\n",
      "Removed: 9\n"
     ]
    }
   ],
   "source": [
    "before = len(df)\n",
    "df = df.drop_duplicates(subset=[\"Number\"], keep=\"last\")\n",
    "after = len(df)\n",
    "\n",
    "print(\"Before:\", before)\n",
    "print(\"After :\", after)\n",
    "print(\"Removed:\", before - after)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6c1e477b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    01781133333\n",
      "2    01727074508\n",
      "4    01716603589\n",
      "6    01337103616\n",
      "8    01766435938\n",
      "Name: Number, dtype: str\n"
     ]
    }
   ],
   "source": [
    "# Ensure Number column is string\n",
    "df['Number'] = df['Number'].astype(str).str.strip()\n",
    "\n",
    "# Add leading 0 if not already present\n",
    "df['Number'] = df['Number'].apply(lambda x: '0' + x if not x.startswith('0') else x)\n",
    "\n",
    "print(df['Number'].head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a61f5286",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'Name': 'zahidur', 'Number': '01781133333'}, {'Name': 'MD Jahidul Islam', 'Number': '01727074508'}, {'Name': 'Shafiqul Islam', 'Number': '01716603589'}, {'Name': 'Mujahidor Rahamanhalo', 'Number': '01337103616'}, {'Name': 'Jahid Hasan', 'Number': '01766435938'}]\n"
     ]
    }
   ],
   "source": [
    "# Remove leading and trailing spaces from Name\n",
    "df[\"Name\"] = df[\"Name\"].str.strip()\n",
    "\n",
    "# Optional: remove extra spaces inside name too (multiple spaces → single space)\n",
    "df[\"Name\"] = df[\"Name\"].str.replace(r'\\s+', ' ', regex=True)\n",
    "\n",
    "# Convert to list of dict\n",
    "result = df.rename(columns={\n",
    "    \"Name\": \"Name\",\n",
    "    \"Number\": \"Number\"\n",
    "}).to_dict(orient=\"records\")\n",
    "\n",
    "print(result[:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "aa5aecb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'Name': 'zahidur', 'Number': '01781133333'}, {'Name': 'MD Jahidul Islam', 'Number': '01727074508'}, {'Name': 'Shafiqul Islam', 'Number': '01716603589'}, {'Name': 'Mujahidor Rahamanhalo', 'Number': '01337103616'}, {'Name': 'Jahid Hasan', 'Number': '01766435938'}]\n",
      "Total valid numbers: 731\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "pattern = r\"01[3-9]\\d{8}\"\n",
    "res_dec = []\n",
    "for i in result:\n",
    "    txt = i[\"Number\"]\n",
    "    matches = re.findall(pattern, txt, re.MULTILINE)\n",
    "    if len(matches) > 1:\n",
    "        for j in matches:\n",
    "            res_dec.append({\"Name\": i[\"Name\"], \"Number\": j})\n",
    "    elif len(matches) == 1:\n",
    "        res_dec.append({\"Name\": i[\"Name\"], \"Number\": matches[0]})\n",
    "print(res_dec[:5])\n",
    "print(\"Total valid numbers:\", len(res_dec))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4755835a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Duplicate numbers found:\n"
     ]
    }
   ],
   "source": [
    "# 🔹 Find duplicate numbers\n",
    "seen = set()\n",
    "duplicates = []\n",
    "\n",
    "for contact in res_dec:\n",
    "    num = contact['Number']\n",
    "    if num in seen:\n",
    "        duplicates.append(contact)\n",
    "    else:\n",
    "        seen.add(num)\n",
    "\n",
    "print(\"Duplicate numbers found:\")\n",
    "for dup in duplicates:\n",
    "    print(dup)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1c62c0de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "After removing duplicates:\n",
      "731\n"
     ]
    }
   ],
   "source": [
    "unique_contacts = []\n",
    "seen = set()\n",
    "\n",
    "for contact in res_dec:\n",
    "    num = contact['Number']\n",
    "    if num not in seen:\n",
    "        unique_contacts.append(contact)\n",
    "        seen.add(num)\n",
    "\n",
    "print(\"After removing duplicates:\")\n",
    "print(len(unique_contacts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "78c1adec",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "with open(\"contacts.json\", \"w\", encoding=\"utf-8\") as f:\n",
    "    json.dump(unique_contacts, f, ensure_ascii=False, indent=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fb76d1ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total entries in JSON: 563\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "with open(\"done.json\", \"r\", encoding=\"utf-8\") as f:\n",
    "    done = json.load(f)\n",
    "print(\"Total entries in JSON:\", len(done))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5c1c2d31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total successful entries: 362\n"
     ]
    }
   ],
   "source": [
    "counter = 0\n",
    "for i in done:\n",
    "    if i['Status'] == \"success\":\n",
    "        counter = counter + 1\n",
    "print(\"Total successful entries:\", counter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fefde580",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Excel file created successfully!\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import pandas as pd\n",
    "\n",
    "\n",
    "# Convert to DataFrame\n",
    "df = pd.DataFrame(done)\n",
    "\n",
    "# Save to Excel\n",
    "df.to_excel(\"done.xlsx\", index=False)\n",
    "\n",
    "print(\"Excel file created successfully!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53a2f96f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "wp",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}