-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_CSV.py
130 lines (113 loc) · 4.29 KB
/
app_CSV.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import pandas as pd
import numpy as np
import cx_Oracle
#Variables Parametros Locales
from Parameters import *
from Credenciales import *
###############################################################
''' Origen SQL
pre_source = pd.read_sql(
query
,con=connection
)
source = pre_source.astype(str
).sort_values(by=Value_to_Order, ascending=ASC, kind='mergesort',ignore_index=False
).reset_index(drop=True)
'''
''' Origen CSV'''
pre_source = pd.read_csv(csv_file_source, sep=f'{delimiter_source}', dtype=str
).sort_values(by=Order_target_Values_by_Headers, ascending=ASC, kind='mergesort',ignore_index=False)
source = pre_source.reset_index(drop=True)
###############################################################
''' Destino CSV'''
try:
pre_target = pd.read_csv(
csv_file_target,sep=f'{delimiter_target}',
encoding = encoding
,dtype=str # STRING / OBJECT
#,header=None # NO HEADER
#,index_col=0 # NO index
).sort_values(by=Order_target_Values_by_Headers, ascending=ASC, kind='mergesort',ignore_index=False
).reset_index(drop=True)
target = pre_target.where(pd.notnull(pre_target), str(None))
except ValueError as e:
print(e)
pre_target = pd.read_csv(
csv_file_target,sep=f'{delimiter_target}',
encoding = encoding
,dtype=str # STRING / OBJECT
#,header=None # NO HEADER
#,index_col=0 # NO index
)
target = pre_target.where(pd.notnull(pre_target), None)
print()
print("==============================================")
print("SHOW | Source Data and Target Data")
print("==============================================")
print(f'Source : ')
print(f'--------')
print(source)
print()
print(f'Target : ')
print(f'---------')
print(target)
###############################################################
print()
try:
print("==============================================")
print("TEST 01 | Compare Amount of rows are equals")
print("==============================================")
#diffe = origen.compare(destino, align_axis=0)
des_count_row = target.shape[0]
ori_count_row = source.shape[0]
print (f"Source Rows = {ori_count_row}")
print (f"Target Rows = {des_count_row}")
print()
except ValueError as e:
print(e)
try:
print("==============================================")
print("TEST 02 | Check the Headers are correct")
print("==============================================")
data_cabeceras = {
'Source_HEADERS':list(source.columns),
'Target_HEADERS':list(target.columns)
}
data_cabeceras_view = pd.DataFrame(data_cabeceras)
data_cabeceras_view['IGUALDAD'] = data_cabeceras_view['Source_HEADERS'] == data_cabeceras_view['Target_HEADERS']
df2=data_cabeceras_view[data_cabeceras_view['IGUALDAD'] == False]
print(data_cabeceras_view)
print('-------------------------------------------')
print(df2)
except:
print('CABECERAS | Headers are NOT equals :')
print()
print(f'Source : {list(source.columns)}')
print(f'- rows : {len(list(source.columns))}')
print(f'Target : {list(target.columns)}')
print(f'- rows : {len(list(target.columns))}')
try:
a = [i for i in list(source.columns) if i not in list(target.columns)]
print()
print(f'Misspelled words are found: {a}')
print()
except ValueError as e:
print(e)
print()
try:
print("==============================================")
print("TEST 03 | Validate the values ")
print("==============================================")
difference = source.compare(target, align_axis=0, result_names=('Source', 'Target'))
#difference.to_csv('output.csv',sep='\t')
print("Diferent values: ")
print()
print(difference)
print()
difference_rows = difference.shape[0]
print(f" Amount of diferent values : {difference_rows/2}")
#print(origen.dtypes) #Debugear inconsistenciaSs
except ValueError as e:
print('\n The number of rows is not the same, or the headers are not in an appropriate order\n')
print()
print(e)