1
|
|
|
""" |
2
|
|
|
DataInput - class to handle data storing to disk (from Pandas Data Frame |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class DataInput: |
7
|
|
|
|
8
|
|
|
@staticmethod |
9
|
|
|
def fn_internal_store_data_frame_to_csv_file(in_dict): |
10
|
|
|
if in_dict['format'].lower() == 'csv': |
11
|
|
|
try: |
12
|
|
|
in_dict['in data frame'].to_csv(path_or_buf = in_dict['name'], |
13
|
|
|
sep = in_dict['field delimiter'], |
14
|
|
|
header = True, |
15
|
|
|
index = False, |
16
|
|
|
encoding = 'utf-8') |
17
|
|
|
except Exception as err: |
18
|
|
|
in_dict['error details'] = err |
19
|
|
|
return in_dict |
20
|
|
|
|
21
|
|
|
@staticmethod |
22
|
|
|
def fn_internal_store_data_frame_to_excel_file(in_dict): |
23
|
|
|
if in_dict['format'].lower() == 'excel': |
24
|
|
|
try: |
25
|
|
|
in_dict['in data frame'].to_excel(excel_writer = in_dict['name'], |
26
|
|
|
engine = 'xlsxwriter', |
27
|
|
|
freeze_panes = (1, 1), |
28
|
|
|
encoding = 'utf-8', |
29
|
|
|
index = False, |
30
|
|
|
verbose = True) |
31
|
|
|
except Exception as err: |
32
|
|
|
in_dict['error details'] = err |
33
|
|
|
return in_dict |
34
|
|
|
|
35
|
|
|
@staticmethod |
36
|
|
|
def fn_internal_store_data_frame_to_json_file(in_dict): |
37
|
|
|
if in_dict['format'].lower() == 'json': |
38
|
|
|
try: |
39
|
|
|
in_dict['in data frame'].to_json(path_or_buf = in_dict['name'], |
40
|
|
|
compression = in_dict['compression']) |
41
|
|
|
except Exception as err: |
42
|
|
|
in_dict['error details'] = err |
43
|
|
|
return in_dict |
44
|
|
|
|
45
|
|
|
@staticmethod |
46
|
|
|
def fn_internal_store_data_frame_to_parquet_file(in_dict): |
47
|
|
|
if in_dict['format'].lower() == 'parquet': |
48
|
|
|
try: |
49
|
|
|
in_dict['in data frame'].to_parquet(path = in_dict['name'], |
50
|
|
|
compression = in_dict['compression'], |
51
|
|
|
use_deprecated_int96_timestamps = True) |
52
|
|
|
except Exception as err: |
53
|
|
|
in_dict['error details'] = err |
54
|
|
|
return in_dict |
55
|
|
|
|
56
|
|
|
@staticmethod |
57
|
|
|
def fn_internal_store_data_frame_to_pickle_file(in_dict): |
58
|
|
|
if in_dict['format'].lower() == 'pickle': |
59
|
|
|
try: |
60
|
|
|
in_dict['in data frame'].to_pickle(path = in_dict['name'], |
61
|
|
|
compression = in_dict['compression']) |
62
|
|
|
except Exception as err: |
63
|
|
|
in_dict['error details'] = err |
64
|
|
|
return in_dict |
65
|
|
|
|