1
|
|
|
""" |
2
|
|
|
DataOutput - class to handle disk file storage |
3
|
|
|
""" |
4
|
|
|
# package facilitating Data Frames manipulation |
5
|
|
|
import pandas |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class DataOutput: |
9
|
|
|
|
10
|
|
|
@staticmethod |
11
|
|
|
def fn_internal_load_csv_file_into_data_frame(in_dict): |
12
|
|
|
if in_dict['format'].lower() == 'csv': |
13
|
|
|
try: |
14
|
|
|
in_dict['out data frame'] = pandas.concat( |
15
|
|
|
[pandas.read_csv(filepath_or_buffer = crt_file, |
16
|
|
|
delimiter = in_dict['field delimiter'], |
17
|
|
|
cache_dates = True, |
18
|
|
|
index_col = None, |
19
|
|
|
memory_map = True, |
20
|
|
|
low_memory = False, |
21
|
|
|
encoding = 'utf-8', |
22
|
|
|
) for crt_file in in_dict['files list']], |
23
|
|
|
sort = False) |
24
|
|
|
except Exception as err: |
25
|
|
|
in_dict['error details'] = err |
26
|
|
|
return in_dict |
27
|
|
|
|
28
|
|
|
@staticmethod |
29
|
|
|
def fn_internal_load_excel_file_into_data_frame(in_dict): |
30
|
|
|
if in_dict['format'].lower() == 'excel': |
31
|
|
|
try: |
32
|
|
|
in_dict['out data frame'] = pandas.concat( |
33
|
|
|
[pandas.read_excel(io = crt_file, |
34
|
|
|
verbose = True, |
35
|
|
|
) for crt_file in in_dict['files list']], |
36
|
|
|
sort = False) |
37
|
|
|
except Exception as err: |
38
|
|
|
in_dict['error details'] = err |
39
|
|
|
return in_dict |
40
|
|
|
|
41
|
|
|
@staticmethod |
42
|
|
|
def fn_internal_load_json_file_into_data_frame(in_dict): |
43
|
|
|
if in_dict['format'].lower() == 'json': |
44
|
|
|
try: |
45
|
|
|
in_dict['out data frame'] = pandas.concat( |
46
|
|
|
[pandas.read_json(path_or_buf = crt_file, |
47
|
|
|
compression = in_dict['compression'], |
48
|
|
|
) for crt_file in in_dict['files list']], |
49
|
|
|
sort = False) |
50
|
|
|
except Exception as err: |
51
|
|
|
in_dict['error details'] = err |
52
|
|
|
return in_dict |
53
|
|
|
|
54
|
|
|
@staticmethod |
55
|
|
|
def fn_internal_load_parquet_file_into_data_frame(in_dict): |
56
|
|
|
if in_dict['format'].lower() == 'parquet': |
57
|
|
|
try: |
58
|
|
|
in_dict['out data frame'] = pandas.concat( |
59
|
|
|
[pandas.read_parquet(path = crt_file, |
60
|
|
|
) for crt_file in in_dict['files list']], |
61
|
|
|
sort = False) |
62
|
|
|
except Exception as err: |
63
|
|
|
in_dict['error details'] = err |
64
|
|
|
return in_dict |
65
|
|
|
|
66
|
|
|
@staticmethod |
67
|
|
|
def fn_internal_load_pickle_file_into_data_frame(in_dict): |
68
|
|
|
if in_dict['format'].lower() == 'pickle': |
69
|
|
|
try: |
70
|
|
|
in_dict['out data frame'] = pandas.concat( |
71
|
|
|
[pandas.read_pickle(path = crt_file, |
72
|
|
|
compression = in_dict['compression'], |
73
|
|
|
) for crt_file in in_dict['files list']], |
74
|
|
|
sort = False) |
75
|
|
|
except Exception as err: |
76
|
|
|
in_dict['error details'] = err |
77
|
|
|
return in_dict |
78
|
|
|
|