forked from ehanson8/marc-data-python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractUniqueNamesSubjectsFromCSV.py
74 lines (65 loc) · 2.38 KB
/
extractUniqueNamesSubjectsFromCSV.py
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
import csv
filename = 'marcFields.csv'
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
personalNames = []
for row in reader:
if row['tag'] == '100':
if row['value'] not in personalNames:
personalNames.append(row['value'])
if row['tag'] == '600':
if row['value'] not in personalNames:
personalNames.append(row['value'])
if row['tag'] == '700':
if row['value'] not in personalNames:
personalNames.append(row['value'])
personalNames.sort()
f = csv.writer(open('personalNamesUnique.csv', 'w'))
f.writerow(['value'])
for name in personalNames:
f.writerow([name])
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
corporateNames = []
for row in reader:
if row['tag'] == '110':
if row['value'] not in corporateNames:
corporateNames.append(row['value'])
if row['tag'] == '610':
if row['value'] not in corporateNames:
corporateNames.append(row['value'])
if row['tag'] == '710':
if row['value'] not in corporateNames:
corporateNames.append(row['value'])
corporateNames.sort()
f = csv.writer(open('corporateNamesUnique.csv', 'w'))
f.writerow(['value'])
for name in corporateNames:
f.writerow([name])
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
miscNames = []
for row in reader:
if row['tag'].startswith('1') and row['tag'] != '100' and row['tag'] != '110':
if row['value'] not in miscNames:
miscNames.append(row['value'])
if row['tag'].startswith('7') and row['tag'] != '700' and row['tag'] != '710':
if row['value'] not in miscNames:
miscNames.append(row['value'])
miscNames.sort()
f = csv.writer(open('miscNamesUnique.csv', 'w'))
f.writerow(['value'])
for name in miscNames:
f.writerow([name])
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
subjects = []
for row in reader:
if row['tag'].startswith('6') and row['tag'] != '600' and row['tag'] != '610':
if row['value'] not in subjects:
subjects.append(row['value'])
subjects.sort()
f = csv.writer(open('subjectsUnique.csv', 'w'))
f.writerow(['value'])
for name in subjects:
f.writerow([name])