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