Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

transformdata-checkpoint.py 6.2 KB

You have to be logged in to leave a comment. Sign In
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  1. import pandas as pd
  2. from datetime import datetime
  3. from datetime import timedelta
  4. def convierte_fecha(fecha):
  5. try:
  6. day,month,year = map(int,fecha.split(sep = "-"))
  7. except:
  8. #print(f"no pude ejecutar {fecha}")
  9. return pd.NaT
  10. return datetime(year,month,day)
  11. def elimina_tilde(str_variable):
  12. replacements = {'Á': 'A',
  13. 'É': 'E',
  14. 'Í': 'I',
  15. 'Ó': 'O',
  16. 'Ú': 'U',
  17. 'Ü': 'U',
  18. }
  19. for a, b in replacements.items():
  20. str_variable = str_variable.astype(str).str.replace(a, b)
  21. return str_variable
  22. def elimina_espacios(col):
  23. if col.dtypes == object:
  24. return (col.astype(str).str.rstrip())
  25. return col
  26. def limpia_rit(str_rit):
  27. return str_rit.replace('--','-')
  28. def limpieza_caracteres(str_col):
  29. replacements = {'-': '',
  30. '\xa0': '',
  31. '\n': ''
  32. }
  33. for a, b in replacements.items():
  34. str_col = str_col.astype(str).str.replace(a, b)
  35. return str_col
  36. def transforma_numero(str_numero):
  37. replacements = {"ún": "1",
  38. "un": "1",
  39. "dós": "2",
  40. "dos": "2",
  41. "tres": "3",
  42. "cuatro": "4",
  43. "cinco": "5",
  44. "seis": "6",
  45. "seís": "6",
  46. "séis": "6",
  47. "siete": "7",
  48. "ocho": "8",
  49. "nueve": "9",
  50. "diez": "10",
  51. "once": "11",
  52. "doce": "12",
  53. "trece": "13",
  54. "dieci": "1",
  55. "veinti": "2",
  56. "veinte": "20"
  57. }
  58. for a, b in replacements.items():
  59. str_numero = str_numero.replace(a, b)
  60. return str_numero
  61. def separa_regiones(str_region):
  62. reemplazar_region = {"DECIMA REGION": "REGION",
  63. "UNDECIMA REGION": "REGION",
  64. "DUODECIMA REGION": "REGION",
  65. "DECIMOCUARTA REGION": "REGION",
  66. "DECIMOQUINTA REGION": "REGION",
  67. "PRIMERA REGION": "REGION",
  68. "SEGUNDA REGION": "REGION",
  69. "TERCERA REGION": "REGION",
  70. "CUARTA REGION": "REGION",
  71. "QUINTA REGION": "REGION",
  72. "SEXTA REGION": "REGION",
  73. "SEPTIMA REGION": "REGION",
  74. "OCTAVA REGION": "REGION",
  75. "NOVENA REGION": "REGION",
  76. "BIOBIO": "REGION DEL BIO BIO",
  77. "AYSEN": "REGION DE AISEN",
  78. "MAGALLANES Y DE LA ANTARTICA CHILENA": "REGION DE MAGALLANES Y ANTARTICA CHILENA"
  79. }
  80. for old, new in reemplazar_region.items():
  81. str_region = str_region.replace(old, new)
  82. return str_region
  83. def transforma_asiento(str_asiento):
  84. if str_asiento.find("JUZGADO DE GARANTIA") != -1 or str_asiento.find("TRIBUNAL DE JUICIO ORAL EN LO PENAL") != -1:
  85. str_asiento = "SANTIAGO"
  86. return str_asiento
  87. def cambio_nombre_juzgados(str_tribunal):
  88. reemplazar_texto = {"1º JUZGADO DE LETRAS": "JUZGADO DE LETRAS",
  89. "6º TRIBUNAL DE JUICIO ORAL EN LO PENAL DE SAN MIGUEL": "SEXTO TRIBUNAL DE JUICIO ORAL EN LO PENAL SANTIAGO",
  90. "10º JUZGADO DE GARANTIA": "DECIMO JUZGADO DE GARANTIA",
  91. "11º JUZGADO DE GARANTIA": "UNDECIMO JUZGADO DE GARANTIA",
  92. "12º JUZGADO DE GARANTIA": "DUODECIMO JUZGADO DE GARANTIA",
  93. "13º JUZGADO DE GARANTIA": "DECIMOTERCER JUZGADO DE GARANTIA",
  94. "14º JUZGADO DE GARANTIA": "DECIMOCUARTO JUZGADO DE GARANTIA",
  95. "15º JUZGADO DE GARANTIA": "DECIMOQUINTO JUZGADO DE GARANTIA",
  96. "TRIBUNAL ORAL EN LO PENAL DE": "TRIBUNAL DE JUICIO ORAL EN LO PENAL",
  97. "1º": "PRIMER",
  98. "2º": "SEGUNDO",
  99. "3º": "TERCER",
  100. "4º": "CUARTO",
  101. "5º": "QUINTO",
  102. "6º": "SEXTO",
  103. "7º": "SEPTIMO",
  104. "8º": "OCTAVO",
  105. "9º": "NOVENO",
  106. "TRIBUNAL DE JUICIO ORAL EN LO PENAL DE DE ": "TRIBUNAL DE JUICIO ORAL EN LO PENAL ",
  107. "TRIBUNAL DE JUICIO ORAL EN LO PENAL DE": "TRIBUNAL DE JUICIO ORAL EN LO PENAL",
  108. "JUZGADO DE GARANTIA DE DE ": "JUZGADO DE GARANTIA ",
  109. "JUZGADO DE GARANTIA DE": "JUZGADO DE GARANTIA",
  110. "JUZGADO DE LETRAS Y GARANTIA DE": "JUZGADO DE LETRAS Y GARANTIA",
  111. "JUZGADO DE LETRAS DE": "JUZGADO DE LETRAS Y GARANTIA",
  112. "LA CALERA": "CALERA",
  113. "PUERTO NATALES": "NATALES",
  114. "PUERTO AYSEN": "AISEN",
  115. "PUERTO CISNES": "CISNES",
  116. "SAN VICENTE DE TAGUA-TAGUA": "SAN VICENTE",
  117. "ACHAO": "QUINCHAO",
  118. "COYHAIQUE": "COIHAIQUE"
  119. }
  120. for old, new in reemplazar_texto.items():
  121. str_tribunal = str_tribunal.replace(old, new)
  122. return str_tribunal
  123. def fechas_cambiadas(row):
  124. if row['DURACION CAUSA'] < 0:
  125. fecha_inicio = row['FECHA TERMINO']
  126. fecha_termino = row['FECHA INGRESO']
  127. row['FECHA INGRESO'] = fecha_termino
  128. row['FECHA TERMINO'] = fecha_inicio
  129. row['DURACION CAUSA'] = row['DURACION CAUSA']*-1
  130. return row
  131. def fecha_programada(row):
  132. if row['FECHA PROGRAMACION AUDIENCIA'] is pd.NaT:
  133. row['FECHA PROGRAMACION AUDIENCIA'] = row['FECHA AUDIENCIA'] - pd.tseries.offsets.Day(row['DIAS AGENDAMIENTO'])
  134. return row
  135. def cambio_termino_causa(str_termino):
  136. return str_termino.replace(".","")
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...