Projekt

Obecné

Profil

Stáhnout (1.15 KB) Statistiky
| Větev: | Revize:
1 04a2b5a4 petrh
# Path to processed data
2 c8f3051b petrh
PROCESSED_DATA_PATH = "ProcessedData/"
3
4 04a2b5a4 petrh
5 c8f3051b petrh
def get_unique_names_from_file(filename, column_number):
6 04a2b5a4 petrh
    """
7 34cf65cd petrh
        Extract set of unique names from file
8 04a2b5a4 petrh
    Args:
9 34cf65cd petrh
        filename: path to processed file
10
        column_number: unique names are expected in csv file on column_number
11 04a2b5a4 petrh
12
    Returns:
13 34cf65cd petrh
        set of unique names
14 04a2b5a4 petrh
    """
15 c8f3051b petrh
    # create set of unique names
16
    name_set = set()
17
18 34cf65cd 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 c8f3051b petrh
26
    return name_set
27
28
29
def export_data_to_csv(filename, data_dict):
30 34cf65cd 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 c8f3051b 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')