-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrangler.py
More file actions
166 lines (136 loc) · 3.93 KB
/
wrangler.py
File metadata and controls
166 lines (136 loc) · 3.93 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
import pandas as pd
import unicodedata
vowelDict = {'á' : 'a', 'ó' : 'o', 'ñ':'n', 'é':'e'}
def strip_accents(text):
try:
text = unicode(text, 'utf-8')
except NameError:
pass
text = unicodedata.normalize('NFD', text)\
.encode('ascii', 'ignore')\
.decode("utf-8")
return str(text)
laptopsdf = pd.read_csv("lapsAmazonImgs.csv")
tvsdf = pd.read_csv("tvsAmazonImgs.csv")
celsdf = pd.read_csv("celsAmazonImgs.csv")
print(laptopsdf.head())
print(tvsdf.head())
print(celsdf.head())
"""
#Laptop Cleaning
lapsbb = laptopsdf["Alt Text"]
lapbrands = []
lapnames = ["" for i in range(len(lapsbb))]
laplens =[] #Stores the number of strings in each field
for k in range(len(lapsbb)):
lap = lapsbb[k].split(" ")
#print(lap)
lapbrands.append(lap[0])
try: #make loop for this, dont keep doing that horror
#print(len(lap))
if(len(lap) > 1):
for i in range(len(lap)):
lapnames[k] += lap[i] + " "
laplens.append(len(lap))
except:
pass
#Cleaning values
lapnames2 = ["" for i in range(len(lapnames))]
for i in range(len(lapnames)):
lapnames2[i] += (strip_accents(lapnames[i]))
if(len(lapnames2) == len(lapbrands)):
tagLaps = [ 1 for i in range(len(lapnames))]
laptopsdf["Laptop Brand"] = lapbrands
laptopsdf["Laptop Model"] = lapnames2
laptopsdf["Tag"] = tagLaps
del laptopsdf['Alt Text']
print(laptopsdf.head())
else:
print('ERROR')
print(lapnames2[0])
print(lapbrands[0])
print(len(lapnames2))
print(len(lapbrands))
"""
#TV cleaning----------------------------------------------
tvsbb = tvsdf["Alt Text"]
tvbrands = []
#tvnames = []
#tvnames2= []
"""
for tv in tvsbb:
tv = tv.split("-")
#print(tv)
tvbrands.append(tv[0])
tvnames.append(tv[1] + tv[2])
tvnames2.append(tv[3])
tvnames += tvnames2
print(len(tvnames))
print(len(tvbrands))
"""
tvnames = ["" for i in range(len(tvsbb))]
tvlens =[] #Stores the number of strings in each field
for k in range(len(tvsbb)):
tvsbb[k] = str(tvsbb[k])
tv = tvsbb[k].split(" ")
#print(lap)
tvbrands.append(tv[0])
try: #make loop for this, dont keep doing that horror
#print(len(lap))
if(len(tv) > 1):
for i in range(len(tv)):
tvnames[k] += tv[i] + " "
tvlens.append(len(tv))
except:
pass
#Cleaning values
tvnames2 = ["" for i in range(len(tvnames))]
for i in range(len(tvnames)):
tvnames2[i] += (strip_accents(tvnames[i]))
if(len(tvnames2) == len(tvbrands)):
tagtvs = [ 2 for i in range(len(tvbrands))]
tvsdf["TV Brand"] = tvbrands
tvsdf["TV Model"] = tvnames2
tvsdf["Tag"] = tagtvs
del tvsdf['Alt Text']
print(tvsdf.head())
else:
print('ERROR')
print(tvnames2[0])
print(tvbrands[0])
print(len(tvnames2))
print(len(tvbrands))
"""
#Cellphone cleaning---------------------------------------
celsAmazon = celsdf["Alt Text"]
Cellbrands = []
Cellnames = [] #List of lists containing the names + details
#List of names
for c in celsAmazon:
c = c.split(" ")
#print(lap)
Cellbrands.append(c[0])
Cellnames.append(c[1:])
Cellnames2 = [[] for i in range(len(Cellnames))]
for i in range(len(Cellnames)):
name = ""
Cellnames2[i] = name
for word in Cellnames[i]:
Cellnames2[i] += word + " "
#Cleaning values
phonenames2 = ["" for i in range(len(Cellnames2))]
for i in range(len(Cellnames2)):
phonenames2[i] += (strip_accents(Cellnames2[i]))
tagCells = [ 3 for i in range(len(Cellbrands))]
celsdf["Cellphone Brand"] = Cellbrands
celsdf["Cellphone Model"] = phonenames2
celsdf["Tag"] = tagCells
del celsdf['Alt Text']
print(celsdf.head())
"""
#print(laptopsdf)
print(tvsdf)
#print(celsdf)
#laptopsdf.to_csv("Laptopsclean.csv", encoding='utf-8')
tvsdf.to_csv("TVsclean.csv", encoding='utf-8')
#celsdf.to_csv("Cellphonesclean.csv", encoding='utf-8')