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 9.1 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 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 = ['level_0_x', 'index_x', 'level_0_y', '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 = ['level_0_x', 'index_x', 'level_0_y', '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_materia, df_rol, how='outer', on=['COD. CORTE','COD. TRIBUNAL','RIT'])
  63. data.save_feather(df_union, 'consolidated_Materia_Rol', path_processed)
  64. click.echo('Generado archivo Feather. Proceso Terminado')
  65. def consolidated_full(path_processed = "data/processed/pjud"):
  66. tqdm.pandas()
  67. df_causas = pd.read_feather(f"{path_processed}/consolidated_Materia_Rol.feather")
  68. df_audiencias = pd.read_feather(f"{path_processed}/processes_Audiencias.feather")
  69. df_consolidado = pd.merge(df_causas,df_audiencias, how='outer', on=['COD. TRIBUNAL','RIT'])
  70. # Unificar RIT y Tribunal en una sola columna para evitar mala interpretacion de causas
  71. df_consolidado['TRIBUNAL-RIT'] = df_consolidado['COD. TRIBUNAL'].map(str) + "-" + df_consolidado['RIT'].map(str)
  72. # Carga Data relacionada a Tipologia de delitos
  73. path_delitos = 'data/processed/delitos'
  74. df_tipologia = pd.read_feather(f"{path_delitos}/clean_Delitos.feather")
  75. df_consolidado = pd.merge(df_consolidado,df_tipologia, how='outer', on=['COD. MATERIA'])
  76. # Carga Data relacionada a Poblacion
  77. df_poblacion = pd.read_feather(f"{path_processed}/processes_DataConsolidada_Poblacion_Jurisdiccion.feather")
  78. df_consolidado = pd.merge(df_consolidado,df_poblacion, how='outer', on=['CORTE','TRIBUNAL'])
  79. columnas_duplicadas = ['index_x', 'index_x','CORTE_x','TRIBUNAL_x','TIPO CAUSA_x','MATERIA_x','FECHA INGRESO_x','AÑO INGRESO_x','FECHA TERMINO_x','AÑO TERMINO_x','MOTIVO TERMINO_x','DURACION CAUSA_x',
  80. 'TOTAL TERMINOS_x','index_y','CORTE_y','TRIBUNAL_y','TIPO CAUSA_y','level_0','index_y','COD. CORTE_y','index_x','index_y']
  81. df_consolidado.drop(columnas_duplicadas, axis='columns', inplace=True)
  82. # Reordenando Nombres de las columnas ...
  83. df_consolidado.rename(columns = {'COD. CORTE_x':'cod_corte',
  84. 'COD. TRIBUNAL':'cod_tribunal',
  85. 'RIT':'rit',
  86. 'COD. MATERIA':'cod_materia',
  87. 'TOTAL INGRESOS POR MATERIAS':'total_ingresos_materia',
  88. 'FECHA INGRESO_y':'fecha_ingreso',
  89. 'AÑO INGRESO_y':'año_ingreso',
  90. 'FECHA TERMINO_y':'fecha_termino',
  91. 'DURACION CAUSA_y':'duracion_causa',
  92. 'MOTIVO TERMINO_y':'motivo_termino',
  93. 'AÑO TERMINO_y':'año_termino',
  94. 'TOTAL TERMINOS_y':'total_terminos',
  95. 'CORTE':'corte',
  96. 'TRIBUNAL':'tribunal',
  97. 'TIPO CAUSA':'tipo_causa',
  98. 'TIPO DE AUDIENCIA':'tipo_audiencia',
  99. 'FECHA PROGRAMACION AUDIENCIA':'fecha_programacion_audiencia',
  100. 'FECHA AUDIENCIA':'fecha_audiencia',
  101. 'DIAS AGENDAMIENTO':'dias_agendamiento',
  102. 'DURACION AUDIENCIA (MIN)':'duracion_audiencia_minutos',
  103. 'TOTAL AUDIENCIAS':'total_audiencias',
  104. 'TRIBUNAL-RIT':'tribunal_rit',
  105. 'MATERIA_y':'materia',
  106. 'TIPOLOGIA MATERIA':'tipologia_materia',
  107. 'VIGENCIA MATERIA':'vigencia_materia',
  108. 'REGION':'region',
  109. 'POBLACION':'poblacion',
  110. 'HOMBRES':'hombres',
  111. 'MUJERES':'mujeres',
  112. 'URBANO':'urbano',
  113. 'RURAL':'rural',
  114. 'COMUNAS':'comunas',
  115. 'JUECES':'dotacion_jueces',
  116. 'ASIENTO':'asiento',
  117. 'TIPO JUZGADO':'tipo_juzgado'
  118. },inplace = True)
  119. df_consolidado = df_consolidado[['region','cod_corte','corte','tribunal_rit','cod_tribunal','rit','tribunal','tipo_juzgado','dotacion_jueces','tipo_causa','fecha_ingreso','año_ingreso','cod_materia','materia',
  120. 'tipologia_materia','vigencia_materia','tipo_audiencia','fecha_programacion_audiencia','fecha_audiencia','dias_agendamiento','duracion_audiencia_minutos','total_audiencias',
  121. 'total_ingresos_materia','total_terminos','fecha_termino','año_termino','duracion_causa','motivo_termino','asiento','comunas','poblacion','hombres','mujeres','urbano','rural']]
  122. # Eliminamos registros sin cod_corte ya que son registros incompletos.
  123. df_consolidado.drop(df_consolidado[df_consolidado['cod_corte'].isnull()].index, inplace=True)
  124. data.save_feather(df_consolidado, 'consolidated_FullData', path_processed)
  125. 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...