-
Notifications
You must be signed in to change notification settings - Fork 0
/
excel_parser.py
63 lines (50 loc) · 1.98 KB
/
excel_parser.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
# This file is used to generate mappings for various excel files containg different entities.
# Imports
import config as cfg
import os
import pandas as pd
from collections import defaultdict
def read_excel_generate_mapping(fname, to_map=True,key=""):
"""This function is used to read the excel file and create a dictionary out of it.
If to_map is true it uses city as the key which is required by ambulance, hospitals,
ngo data. Else we use other keys such as yoga or music or helpline nos.
"""
pre = os.path.dirname(os.path.realpath(__file__))
path = os.path.join(pre, fname)
mappings = defaultdict(list)
df = pd.read_excel(path)
if to_map:
df.City = df.City.str.lower()
for index, row in df.iterrows():
mappings[row.City].append(row)
else:
for index, row in df.iterrows():
mappings[key].append(row)
return mappings
if __name__ == '__main__':
ngo = read_excel_generate_mapping(cfg.excel_path["ngo"])
food = read_excel_generate_mapping(cfg.excel_path["food"])
hospital = read_excel_generate_mapping(cfg.excel_path["hospital"])
yoga = read_excel_generate_mapping(cfg.excel_path["yoga"], to_map=False, key="yoga")
music = read_excel_generate_mapping(cfg.excel_path["music"], to_map=False, key="music")
emergency = read_excel_generate_mapping(cfg.excel_path["emergency"], to_map=False, key="emergency")
# print(ngo.keys())
# print(ngo["sangli"][0][3])
# print("========================================")
# print(ngo["sangli"][1])
# print(food.keys())
# print(food["sangli"][0][2])
# print("========================================")
# print(food["kolhapur"][1])
# print(food.keys())
# print(hospital["sangli"][0][2])
# print("========================================")
# print(hospital["kolhapur"][1])
# print(yoga.keys())
# print(yoga["yoga"][0])
# print("========================================")
# print(music.keys())
# print(music["music"][0])
# print("========================================")
# print(emergency.keys())
# print(emergency["emergency"][0])