1 |
9990127e
|
petrh
|
# Path to processed data
|
2 |
b3262a44
|
petrh
|
PROCESSED_DATA_PATH = "ProcessedData/"
|
3 |
|
|
|
4 |
9990127e
|
petrh
|
|
5 |
b3262a44
|
petrh
|
def get_unique_names_from_file(filename, column_number):
|
6 |
9990127e
|
petrh
|
"""
|
7 |
cecb4388
|
petrh
|
Extract set of unique names from file
|
8 |
9990127e
|
petrh
|
Args:
|
9 |
cecb4388
|
petrh
|
filename: path to processed file
|
10 |
|
|
column_number: unique names are expected in csv file on column_number
|
11 |
9990127e
|
petrh
|
|
12 |
|
|
Returns:
|
13 |
cecb4388
|
petrh
|
set of unique names
|
14 |
9990127e
|
petrh
|
"""
|
15 |
b3262a44
|
petrh
|
# create set of unique names
|
16 |
|
|
name_set = set()
|
17 |
|
|
|
18 |
cecb4388
|
petrh
|
with open(filename, "r") as file:
|
19 |
|
|
# go through every line of line
|
20 |
|
|
for x in file:
|
21 |
|
|
# split by csv splitter ;
|
22 |
|
|
array = x.split(";")
|
23 |
|
|
# add string from chosen column to set
|
24 |
|
|
name_set.add(array[column_number])
|
25 |
b3262a44
|
petrh
|
|
26 |
|
|
return name_set
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
def export_data_to_csv(filename, data_dict):
|
30 |
cecb4388
|
petrh
|
"""
|
31 |
|
|
Takes data_dict and export it into a csv file
|
32 |
|
|
Args:
|
33 |
|
|
filename: name of exported file
|
34 |
|
|
data_dict: dictionary containing data from DatasetProcessor
|
35 |
|
|
"""
|
36 |
b3262a44
|
petrh
|
with open(PROCESSED_DATA_PATH + filename[12:], "w+") as file:
|
37 |
|
|
|
38 |
|
|
for date in data_dict:
|
39 |
|
|
for data in data_dict[date]:
|
40 |
|
|
file.write(data_dict[date][data].to_csv() + '\n')
|