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

dataconsolidated.py 20 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
  1. import os
  2. import pandas as pd
  3. import numpy as np
  4. import click
  5. from tqdm import tqdm
  6. from unicodedata import normalize
  7. from pjud import data
  8. def consolidated_materia(path_processed = "data/processed/pjud"):
  9. tqdm.pandas()
  10. df_ingresos_materia = pd.read_feather(f"{path_processed}/processes_IngresosMateria.feather")
  11. df_termino_materia = pd.read_feather(f"{path_processed}/processes_TerminosMateria.feather")
  12. df_fulldata_materia = pd.merge(df_ingresos_materia, df_termino_materia, how='outer', on=['COD. TRIBUNAL','RIT','COD. MATERIA'])
  13. columnas_drop = ['index_x', 'index_y', 'MES INGRESO', 'MES TERMINO']
  14. df_fulldata_materia.drop(columnas_drop, axis = 'columns', inplace = True)
  15. click.echo('Transformando data faltante ...')
  16. df_fulldata_materia = df_fulldata_materia.progress_apply(data.transformdata.faltantes_materia, axis=1)
  17. columnas_drop = ['TIPO CAUSA_y', 'MATERIA_y', 'TRIBUNAL_y', 'COD. CORTE_y', 'CORTE_y', 'FECHA INGRESO_y']
  18. df_fulldata_materia.drop(columnas_drop, axis = 'columns', inplace = True)
  19. df_fulldata_materia.rename(columns = {'COD. CORTE_x':'COD. CORTE',
  20. 'CORTE_x':'CORTE',
  21. 'TRIBUNAL_x':'TRIBUNAL',
  22. 'TIPO CAUSA_x':'TIPO CAUSA',
  23. 'MATERIA_x':'MATERIA',
  24. 'FECHA INGRESO_x':'FECHA INGRESO'
  25. }, inplace = True)
  26. filtro_oral = df_fulldata_materia[df_fulldata_materia['TRIBUNAL'].str.contains('ORAL')]
  27. filtro_garantia = df_fulldata_materia[df_fulldata_materia['TRIBUNAL'].str.contains('GARANTIA')]
  28. data.save_feather(df_fulldata_materia, 'consolidated_Materia', path_processed)
  29. data.save_feather(filtro_oral, 'consolidated_JuicioOralesMateria', path_processed)
  30. data.save_feather(filtro_garantia, 'consolidated_CausasGarantiaMateria', path_processed)
  31. click.echo('Generado archivo Feather. Proceso Terminado')
  32. def consolidated_rol(path_processed = "data/processed/pjud"):
  33. tqdm.pandas()
  34. df_ingresos_rol = pd.read_feather(f"{path_processed}/processes_IngresosRol.feather")
  35. df_termino_rol = pd.read_feather(f"{path_processed}/processes_TerminosRol.feather")
  36. df_fulldata_rol = pd.merge(df_ingresos_rol, df_termino_rol, how='outer', on=['COD. TRIBUNAL','RIT'])
  37. columnas_drop = ['index_x', 'index_y', 'MES INGRESO', 'MES TERMINO']
  38. df_fulldata_rol.drop(columnas_drop, axis = 'columns', inplace = True)
  39. click.echo('Transformando data faltante ...')
  40. df_fulldata_rol = df_fulldata_rol.progress_apply(data.transformdata.faltantes_rol, axis=1)
  41. columnas_drop = ['TIPO CAUSA_y', 'TRIBUNAL_y', 'COD. CORTE_y', 'CORTE_y', 'FECHA INGRESO_y']
  42. df_fulldata_rol.drop(columnas_drop, axis = 'columns', inplace = True)
  43. df_fulldata_rol.rename(columns = {'COD. CORTE_x':'COD. CORTE',
  44. 'CORTE_x':'CORTE',
  45. 'TRIBUNAL_x':'TRIBUNAL',
  46. 'TIPO CAUSA_x':'TIPO CAUSA',
  47. 'MATERIA_x':'MATERIA',
  48. 'FECHA INGRESO_x':'FECHA INGRESO'
  49. }, inplace = True)
  50. causas_top = df_fulldata_rol[df_fulldata_rol['TRIBUNAL'].str.contains('ORAL')]
  51. causas_garantia = df_fulldata_rol[df_fulldata_rol['TRIBUNAL'].str.contains('GARANTIA')]
  52. df_rit_cero = df_fulldata_rol[df_fulldata_rol['RIT'].str.startswith("0-")]
  53. df_fulldata_rol.drop(df_rit_cero.index, axis=0, inplace=True)
  54. data.save_feather(df_fulldata_rol, 'consolidated_Rol', path_processed)
  55. data.save_feather(causas_top, 'consolidated_JuicioOralesRol', path_processed)
  56. data.save_feather(causas_garantia, 'consolidated_CausasGarantiaRol', path_processed)
  57. click.echo('Generado archivo Feather. Proceso Terminado')
  58. def consolidated_materia_rol(path_processed = "data/processed/pjud"):
  59. tqdm.pandas()
  60. df_materia = pd.read_feather(f"{path_processed}/consolidated_Materia.feather")
  61. df_rol = pd.read_feather(f"{path_processed}/consolidated_Rol.feather")
  62. df_union = pd.merge(df_rol, df_materia, how='left', on=['COD. CORTE','COD. TRIBUNAL','RIT'], indicator=True)
  63. columnas_duplicadas = ['index_x', 'index_y','CORTE_y', 'TRIBUNAL_y',
  64. 'TIPO CAUSA_y', 'FECHA INGRESO_y',
  65. 'AÑO INGRESO_y', 'FECHA TERMINO_y',
  66. 'AÑO TERMINO_y', 'MOTIVO TERMINO_y','DURACION CAUSA_y',
  67. 'TOTAL TERMINOS_y', '_merge']
  68. df_union.drop(columnas_duplicadas, axis='columns', inplace=True)
  69. df_union.rename(columns = {'CORTE_x':'CORTE',
  70. 'TRIBUNAL_x':'TRIBUNAL',
  71. 'TIPO CAUSA_x':'TIPO CAUSA',
  72. 'FECHA INGRESO_x':'FECHA INGRESO',
  73. 'AÑO INGRESO_x':'AÑO INGRESO',
  74. 'FECHA TERMINO_x':'FECHA TERMINO',
  75. 'AÑO TERMINO_x':'AÑO TERMINO',
  76. 'MOTIVO TERMINO_x':'MOTIVO TERMINO',
  77. 'DURACION CAUSA_x':'DURACION CAUSA',
  78. 'TOTAL TERMINOS_x':'TOTAL TERMINOS'
  79. },inplace = True)
  80. data.save_feather(df_union, 'consolidated_Materia_Rol', path_processed)
  81. click.echo('Generado archivo Feather. Proceso Terminado')
  82. def consolidated_fulldata_causa(path_processed = "data/processed/pjud"):
  83. tqdm.pandas()
  84. path_delitos = 'data/processed/delitos'
  85. df_causas = pd.read_feather(f"{path_processed}/consolidated_Materia_Rol.feather")
  86. df_tipologia = pd.read_feather(f"{path_delitos}/clean_Delitos.feather")
  87. df_poblacion = pd.read_feather(f"{path_processed}/processes_DataConsolidada_Poblacion_Jurisdiccion.feather")
  88. # Unificar RIT y Tribunal en una sola columna para evitar mala interpretacion de causas
  89. df_causas['TRIBUNAL-RIT'] = df_causas['COD. TRIBUNAL'].map(str) + "-" + df_causas['RIT'].map(str)
  90. # Carga Data relacionada a Tipologia de delitos
  91. df_causa_tipologia = pd.merge(df_causas,df_tipologia, how='left', on=['COD. MATERIA'])
  92. columnas_duplicadas = ['index_x', 'MATERIA_x','index_y']
  93. df_causa_tipologia.drop(columnas_duplicadas, axis='columns', inplace=True)
  94. df_causa_tipologia.rename(columns = {'MATERIA_y':'MATERIA'}, inplace=True)
  95. # Carga Data relacionada a Poblacion
  96. df_fulldatacausa = pd.merge(df_causa_tipologia, df_poblacion, how='left', on=['CORTE','TRIBUNAL'])
  97. columnas_duplicadas = ['index']
  98. df_fulldatacausa.drop(columnas_duplicadas, axis='columns', inplace=True)
  99. # Reordenando Nombres de las columnas ...
  100. df_fulldatacausa.rename(columns = { 'COD. CORTE':'cod_corte',
  101. 'COD. TRIBUNAL':'cod_tribunal',
  102. 'RIT':'rit',
  103. 'COD. MATERIA':'cod_materia',
  104. 'TOTAL INGRESOS POR MATERIAS':'total_ingresos_materia',
  105. 'FECHA INGRESO':'fecha_ingreso',
  106. 'AÑO INGRESO':'año_ingreso',
  107. 'FECHA TERMINO':'fecha_termino',
  108. 'DURACION CAUSA':'duracion_causa',
  109. 'MOTIVO TERMINO':'motivo_termino',
  110. 'AÑO TERMINO':'año_termino',
  111. 'TOTAL TERMINOS':'total_terminos',
  112. 'CORTE':'corte',
  113. 'TRIBUNAL':'tribunal',
  114. 'TIPO CAUSA':'tipo_causa',
  115. 'TRIBUNAL-RIT':'tribunal_rit',
  116. 'MATERIA':'materia',
  117. 'TIPOLOGIA MATERIA':'tipologia_materia',
  118. 'VIGENCIA MATERIA':'vigencia_materia',
  119. 'REGION':'region',
  120. 'POBLACION':'poblacion',
  121. 'HOMBRES':'hombres',
  122. 'MUJERES':'mujeres',
  123. 'URBANO':'urbano',
  124. 'RURAL':'rural',
  125. 'COMUNAS':'comunas',
  126. 'JUECES':'dotacion_jueces',
  127. 'ASIENTO':'asiento',
  128. 'TIPO JUZGADO':'tipo_juzgado'
  129. },inplace = True)
  130. df_fulldatacausa = df_fulldatacausa[['region','cod_corte','corte','tribunal_rit','cod_tribunal','rit','tribunal','tipo_juzgado','dotacion_jueces','tipo_causa','fecha_ingreso','año_ingreso','cod_materia','materia',
  131. 'tipologia_materia','vigencia_materia','total_ingresos_materia','total_terminos','fecha_termino','año_termino','duracion_causa','motivo_termino','asiento','comunas','poblacion',
  132. 'hombres','mujeres','urbano','rural']]
  133. data.save_feather(df_fulldatacausa, 'consolidated_FullData_Causa', path_processed)
  134. click.echo('Generado archivo Feather. Proceso Terminado')
  135. def consolidated_fulldata_audiencias(path_processed = "data/processed/pjud"):
  136. tqdm.pandas()
  137. df_audiencias = pd.read_feather(f"{path_processed}/processes_Audiencias.feather")
  138. df_poblacion = pd.read_feather(f"{path_processed}/processes_DataConsolidada_Poblacion_Jurisdiccion.feather")
  139. df_audiencias['TRIBUNAL-RIT'] = df_audiencias['COD. TRIBUNAL'].map(str) + "-" + df_audiencias['RIT'].map(str)
  140. df_audiencias['AÑO INGRESO'] = df_audiencias['RIT'].progress_apply(data.cleandata.obtiene_año)
  141. columnas_duplicadas = ['level_0', 'index']
  142. df_audiencias.drop(columnas_duplicadas, axis='columns', inplace=True)
  143. df_fulldataaudiencias = pd.merge(df_audiencias, df_poblacion, how='left', on=['CORTE','TRIBUNAL'])
  144. columnas_duplicadas = ['index']
  145. df_fulldataaudiencias.drop(columnas_duplicadas, axis='columns', inplace=True)
  146. df_fulldataaudiencias.rename(columns = {'COD. CORTE':'cod_corte',
  147. 'COD. TRIBUNAL':'cod_tribunal',
  148. 'RIT':'rit',
  149. 'CORTE':'corte',
  150. 'TRIBUNAL':'tribunal',
  151. 'TIPO CAUSA':'tipo_causa',
  152. 'TIPO DE AUDIENCIA':'tipo_audiencia',
  153. 'FECHA PROGRAMACION AUDIENCIA':'fecha_programacion_audiencia',
  154. 'FECHA AUDIENCIA':'fecha_audiencia',
  155. 'DIAS AGENDAMIENTO':'dias_agendamiento',
  156. 'DURACION AUDIENCIA (MIN)':'duracion_audiencia_minutos',
  157. 'TOTAL AUDIENCIAS':'total_audiencias',
  158. 'TRIBUNAL-RIT':'tribunal_rit',
  159. 'AÑO INGRESO':'año_ingreso',
  160. 'REGION':'region',
  161. 'POBLACION':'poblacion',
  162. 'HOMBRES':'hombres',
  163. 'MUJERES':'mujeres',
  164. 'URBANO':'urbano',
  165. 'RURAL':'rural',
  166. 'COMUNAS':'comunas',
  167. 'JUECES':'dotacion_jueces',
  168. 'ASIENTO':'asiento',
  169. 'TIPO JUZGADO':'tipo_juzgado'
  170. },inplace = True)
  171. df_fulldataaudiencias = df_fulldataaudiencias[['region','cod_corte','corte','tribunal_rit','cod_tribunal','rit','tribunal','tipo_juzgado','dotacion_jueces','tipo_causa','año_ingreso',
  172. 'tipo_audiencia','fecha_programacion_audiencia','fecha_audiencia','dias_agendamiento','duracion_audiencia_minutos','total_audiencias',
  173. 'asiento','comunas','poblacion','hombres','mujeres','urbano','rural']]
  174. data.save_feather(df_fulldataaudiencias, 'consolidated_FullData_Audiencias', path_processed)
  175. click.echo('Generado archivo Feather. Proceso Terminado')
  176. def consolidated_fulldata_inventario(path_processed = "data/processed/pjud"):
  177. tqdm.pandas()
  178. path = "data/processed/delitos"
  179. df_inventario = pd.read_feather(f"{path_processed}/processes_Inventario.feather")
  180. df_tipologia = pd.read_feather(f"{path}/clean_Delitos.feather")
  181. df_poblacion = pd.read_feather(f"{path_processed}/processes_DataConsolidada_Poblacion_Jurisdiccion.feather")
  182. df_inventario['TRIBUNAL-RIT'] = df_inventario['COD. TRIBUNAL'].map(str) + "-" + df_inventario['RIT'].map(str)
  183. df_inventario['AÑO INGRESO'] = df_inventario['RIT'].progress_apply(data.cleandata.obtiene_año)
  184. columnas_duplicadas = ['index']
  185. df_inventario.drop(columnas_duplicadas, axis='columns', inplace=True)
  186. df_inventario_tipologia = pd.merge(df_inventario,df_tipologia, how='left', on=['COD. MATERIA'])
  187. columnas_duplicadas = ['index', 'MATERIA_x']
  188. df_inventario_tipologia.drop(columnas_duplicadas, axis='columns', inplace=True)
  189. df_inventario_tipologia.rename(columns = {'MATERIA_y':'MATERIA'}, inplace=True)
  190. df_fulldatainventario = pd.merge(df_inventario_tipologia, df_poblacion, how='left', on=['CORTE','TRIBUNAL'])
  191. columnas_duplicadas = ['index']
  192. df_fulldatainventario.drop(columnas_duplicadas, axis='columns', inplace=True)
  193. df_fulldatainventario.rename(columns = {'COD. CORTE':'cod_corte',
  194. 'COD. TRIBUNAL':'cod_tribunal',
  195. 'RIT':'rit',
  196. 'CORTE':'corte',
  197. 'TRIBUNAL':'tribunal',
  198. 'COMPETENCIA':'competencia',
  199. 'TIPO CAUSA':'tipo_causa',
  200. 'COD. MATERIA':'cod_materia',
  201. 'TIPO ULT. DILIGENCIA':'tipo_ultima_diligencia',
  202. 'FECHA ULT. DILIGENCIA':'fecha_ultima_diligencia',
  203. 'FECHA INGRESO':'fecha_ingreso',
  204. 'AÑO INGRESO':'año_ingreso',
  205. 'TOTAL INVENTARIO':'total_inventario',
  206. 'TRIBUNAL-RIT':'tribunal_rit',
  207. 'MATERIA':'materia',
  208. 'TIPOLOGIA MATERIA':'tipologia_materia',
  209. 'VIGENCIA MATERIA':'vigencia_materia',
  210. 'REGION':'region',
  211. 'POBLACION':'poblacion',
  212. 'HOMBRES':'hombres',
  213. 'MUJERES':'mujeres',
  214. 'URBANO':'urbano',
  215. 'RURAL':'rural',
  216. 'COMUNAS':'comunas',
  217. 'JUECES':'dotacion_jueces',
  218. 'ASIENTO':'asiento',
  219. 'TIPO JUZGADO':'tipo_juzgado'
  220. },inplace = True)
  221. df_fulldatainventario = df_fulldatainventario[['region','cod_corte','corte','tribunal_rit','cod_tribunal','rit','tribunal','competencia','tipo_juzgado','dotacion_jueces','tipo_causa',
  222. 'año_ingreso','fecha_ingreso','cod_materia','materia','tipologia_materia','vigencia_materia','tipo_ultima_diligencia','fecha_ultima_diligencia',
  223. 'total_inventario','asiento','comunas','poblacion','hombres','mujeres','urbano','rural']]
  224. data.save_feather(df_fulldatainventario, 'consolidated_FullData_Inventario', path_processed)
  225. click.echo('Generado archivo Feather. Proceso Terminado')
  226. def consolidated_fulldata_duracion(path_processed = "data/processed/pjud"):
  227. tqdm.pandas()
  228. df_duracion = pd.read_feather(f"{path_processed}/processes_Duraciones.feather")
  229. df_poblacion = pd.read_feather(f"{path_processed}/processes_DataConsolidada_Poblacion_Jurisdiccion.feather")
  230. df_duracion['TRIBUNAL-RIT'] = df_duracion['COD. TRIBUNAL'].map(str) + "-" + df_duracion['RIT'].map(str)
  231. df_duracion['AÑO INGRESO'] = df_duracion['RIT'].progress_apply(data.cleandata.obtiene_año)
  232. columnas_duplicadas = ['index']
  233. df_duracion.drop(columnas_duplicadas, axis='columns', inplace=True)
  234. df_fulldataduracion = pd.merge(df_duracion, df_poblacion, how='left', on=['CORTE','TRIBUNAL'])
  235. columnas_duplicadas = ['index']
  236. df_fulldataduracion.drop(columnas_duplicadas, axis='columns', inplace=True)
  237. df_fulldataduracion.rename(columns = { 'COD. CORTE':'cod_corte',
  238. 'COD. TRIBUNAL':'cod_tribunal',
  239. 'RIT':'rit',
  240. 'CORTE':'corte',
  241. 'TRIBUNAL':'tribunal',
  242. 'TIPO CAUSA':'tipo_causa',
  243. 'FECHA INGRESO':'fecha_ingreso',
  244. 'AÑO INGRESO':'año_ingreso',
  245. 'FECHA TERMINO':'fecha_termino',
  246. 'MES TERMINO':'mes_termino',
  247. 'AÑO TERMINO':'año_termino',
  248. 'TOTAL TERMINOS':'total_terminos',
  249. 'DURACIÓN CAUSA':'duracion_causa',
  250. 'TRIBUNAL-RIT':'tribunal_rit',
  251. 'MOTIVO TERMINO':'motivo_termino',
  252. 'REGION':'region',
  253. 'POBLACION':'poblacion',
  254. 'HOMBRES':'hombres',
  255. 'MUJERES':'mujeres',
  256. 'URBANO':'urbano',
  257. 'RURAL':'rural',
  258. 'COMUNAS':'comunas',
  259. 'JUECES':'dotacion_jueces',
  260. 'ASIENTO':'asiento',
  261. 'TIPO JUZGADO':'tipo_juzgado'
  262. },inplace = True)
  263. df_fulldataduracion = df_fulldataduracion[['region','cod_corte','corte','tribunal_rit','cod_tribunal','rit','tribunal','tipo_juzgado','dotacion_jueces','tipo_causa',
  264. 'año_ingreso','fecha_ingreso','año_termino','mes_termino','fecha_termino','motivo_termino','total_terminos','duracion_causa',
  265. 'asiento','comunas','poblacion','hombres','mujeres','urbano','rural']]
  266. data.save_feather(df_fulldataduracion, 'consolidated_FullData_Duracion', path_processed)
  267. click.echo('Generado archivo Feather. Proceso Terminado')
Tip!

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

Comments

Loading...