-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverting_phone_number.py
More file actions
170 lines (118 loc) · 4.29 KB
/
Copy pathconverting_phone_number.py
File metadata and controls
170 lines (118 loc) · 4.29 KB
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
"""import pandas as pd
import numpy as np
# Load CSV
df = pd.read_csv('lauriethepauth__chien_data.csv')
# Cleaning function
def make_dialable(raw):
if pd.isna(raw):
return ""
return str(raw).replace("(0)", "").replace(".", "")
# Apply cleaning
df['phone_number'] = df['phone_number'].apply(make_dialable)
# Preview result
print(df['phone_number'].head())
# Save to new file
df.to_csv('phone_cleaned.csv', index=False, encoding='utf-8')
print("✔ Cleaned CSV saved as phone_cleaned.csv")
import pandas as pd
import numpy as np
df = pd.read_csv('lauriethepaut__centrale_data.csv')
def make_dialable(raw):
if pd.isna(raw):
return ""
number = str(raw).replace(".", "") # remove dots
if number.startswith("0"):
number = number[1:] # remove leading 0
return "+33" + number # add country code
df['Phone Number'] = df['Phone Number'].apply(make_dialable)
print(df['Phone Number'].head())
df.to_csv('phone_cleaned__centrale_data.csv', index=False, encoding = 'utf-8')
"""
"""
import numpy as np
import pandas as pd
# Load CSV
df = pd.read_csv('phone_cleaned__chien_data.csv')
df.rename(columns={
'url': 'URL',
'company_name': 'Company Name',
'first_name':'First Name',
'last_name':'Last Name',
'phone_number':'Phone Number',
'zip_code':'Zipcode',
'dog_breed':'Dog Breed',
'address':'Address',
'website_url':'Website Url',
'street_number': 'Street Number',
'city':'City',
}, inplace=True)
print(df.columns.tolist())
df.to_csv('phone_cleaned__chien_data_renamed.csv', index=False, encoding='utf-8')
"""
"""
import pandas as pd
# Load the two CSV files
df1 = pd.read_csv('chien.csv')
df2 = pd.read_csv('centrale.csv')
# Get the list of columns
columns1 = set(df1.columns.tolist())
columns2 = set(df2.columns.tolist())
# Columns in both files
common_columns = columns1 & columns2
print("Common Columns:", common_columns)
# Columns only in first file
only_in_df1 = columns1 - columns2
print("Columns only in first file:", only_in_df1)
# Columns only in second file
only_in_df2 = columns2 - columns1
print("Columns only in second file:", only_in_df2)
"""
# import pandas as pd
# # Load both CSVs
# df1 = pd.read_csv('centrale.csv')
# df2 = pd.read_csv('chien.csv')
# # Make a list of columns in df2 that are NOT in df1, except the 'Phone Number' key
# additional_columns = [col for col in df2.columns if col not in df1.columns and col != 'Phone Number']
# # Merge df2 into df1 on 'Phone Number', keeping only additional columns
# merged_df = pd.merge(df1, df2[['Phone Number'] + additional_columns], on='Phone Number', how='outer')
# # Optional: preview result
# print(merged_df.head())
# # Save merged CSV
# merged_df.to_csv('Merged.csv', index=False, encoding='utf-8')
# print("Merged.csv")
# import pandas as pd
# # Load both CSVs
# df1 = pd.read_csv('centrale.csv')
# df2 = pd.read_csv('chien.csv')
# # Start with all columns from df1
# merged_df = df1.copy()
# # Merge rows from df2 based on Phone Number
# for index, row in df2.iterrows():
# phone = row['Phone Number']
# if phone in merged_df['Phone Number'].values:
# # Phone number exists: update only empty columns in merged_df
# for col in df2.columns:
# if col != 'Phone Number' and (col not in merged_df.columns or merged_df.loc[merged_df['Phone Number'] == phone, col].iloc[0] == ''):
# if col not in merged_df.columns:
# merged_df[col] = ''
# merged_df.loc[merged_df['Phone Number'] == phone, col] = row[col]
# else:
# # Phone number doesn't exist: append the row
# merged_df = pd.concat([merged_df, pd.DataFrame([row])], ignore_index=True)
# # Fill remaining NaN with empty string
# merged_df = merged_df.fillna('')
# # Preview
# print(merged_df.head())
# # Save final merged CSV
# merged_df.to_csv('Merged_exact.csv', index=False, encoding='utf-8')
# print(" Merged_exact.csv saved!")
import pandas as pd
# Load CSVs
df1 = pd.read_csv('centrale.csv')
df2 = pd.read_csv('chien.csv')
# Convert phone numbers to set for fast comparison
phones_df1 = set(df1['Phone Number'])
phones_df2 = set(df2['Phone Number'])
# Intersection = phone numbers present in both files
common_phones = phones_df1 & phones_df2
print(f"Number of phone numbers present in both files: {len(common_phones)}")