-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasei.py
More file actions
55 lines (45 loc) · 1.33 KB
/
Copy pathcasei.py
File metadata and controls
55 lines (45 loc) · 1.33 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
#goes through and marks any non number or character differences as dupes
#not always valed, eg 29 != 2,9
import pandas as pd
import glob
import re
import sys
if len(sys.argv) > 1:
start_num = int(sys.argv[1])
else:
start_num = 0
regex = re.compile('[^a-zA-Z0-9\*]')
def j_s(st):
return regex.sub('', st.lower().replace("&", "and"))
look_at_folder = ".\SH_data\current_targets"
file_sub = ""
file_list = glob.glob(look_at_folder + "\\" + file_sub + "*")
edited = 0
group_num = 0
for f in file_list:
changed = False
df = pd.read_csv(f)
uni = df[df.columns[0]].tolist()
uni = [j_s(u) for u in uni]
uni = [l for l in uni if uni.count(l) > 1]
uni = list(set(uni))
labels = []
group_num = start_num
for u in uni:
group_num += 1
labels.append([u, group_num, "ahi"])
for label in labels:
targets = ([ j_s(x) == label[0] for x in df[df.columns[0]] ])
rows = df.index[targets]
for row in rows:
if (df.iloc[row]['group'] != -1) :
continue
df.iat[row, 4] = label[1]
df.iat[row, 5] = label[2]
if not changed : changed = (len(rows) > 0)
if (changed):
df.to_csv(f, index = False)
edited += 1
print(f)
print("Edited", edited, "files")
print("Created", group_num, "groups")