-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcel_to_dictionary
More file actions
61 lines (35 loc) · 951 Bytes
/
Excel_to_dictionary
File metadata and controls
61 lines (35 loc) · 951 Bytes
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
import csv
import glob
import os
from collections import defaultdict
# Checking file in directory
path = '#Directory Path'
extension = 'csv'
os.chdir(path)
result = [i for i in glob.glob('*.{}'.format(extension))]
# print(result)
paths = []
header = []
values = []
header1 = []
values1 = []
d = []
for i in range(0, len(result)):
paths.append(f'{path}/{result[i]}')
for i in range(0, len(paths)):
with open(f'{paths[i]}') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
header.append(row[0])
values.append(row[1])
# print(header)
# print(values)
d["string{0}".format(i)] = dict(zip(header, values))
header = []
values = []
# (d['string0'])
dd = defaultdict(list)
for d in (d['string0'], d['string1']): # you can list as many input dicts as you want here
for key, value in d.items():
dd[key].append(value)
print(dd)