11import pandas as pd
22import json
33
4- csv_file = ' Hospitales_de_Espaadb.csv'
4+ csv_file = " Hospitales_de_Espaadb.csv"
55df = pd .read_csv (csv_file )
66
77json_dict = {}
88
9+
910def to_title_case (value , default = "Desconocido" ):
1011 if pd .isna (value ) or value == "" :
1112 return default
1213 return str (value ).strip ().title ()
1314
15+
1416for index , row in df .iterrows ():
15- hospital_name = to_title_case (row [' NOMBRE' ])
17+ hospital_name = to_title_case (row [" NOMBRE" ])
1618 json_dict [hospital_name ] = {
17- "collecting_institution_address" : to_title_case (row ['DIRECCION' ]),
18- "collecting_institution_email" : row ['EMAIL' ].strip () if not pd .isna (row ['EMAIL' ]) else "Desconocido" ,
19- "collecting_institution_finalidad" : to_title_case (row ['FINALIDAD_ASISITENCIAL' ]),
20- "geo_loc_state" : to_title_case (row ['COMUNIDADES' ]),
21- "geo_loc_region" : to_title_case (row .get ('PROVINCIAS' , None )),
22- "geo_loc_city" : to_title_case (row .get ('MUNICIPIOS' , None )),
23- "geo_loc_country" : to_title_case (row .get ('pais' , None ), default = "Spain" ),
24- "submitting_institution" : "" ,
25- "submitting_institution_address" : "" ,
26- "submitting_institution_email" : ""
19+ "collecting_institution_address" : to_title_case (row ["DIRECCION" ]),
20+ "collecting_institution_email" : (
21+ row ["EMAIL" ].strip () if not pd .isna (row ["EMAIL" ]) else "Desconocido"
22+ ),
23+ "collecting_institution_finalidad" : to_title_case (
24+ row ["FINALIDAD_ASISITENCIAL" ]
25+ ),
26+ "geo_loc_state" : to_title_case (row ["COMUNIDADES" ]),
27+ "geo_loc_region" : to_title_case (row .get ("PROVINCIAS" , None )),
28+ "geo_loc_city" : to_title_case (row .get ("MUNICIPIOS" , None )),
29+ "geo_loc_country" : to_title_case (row .get ("pais" , None ), default = "Spain" ),
30+ "submitting_institution" : "" ,
31+ "submitting_institution_address" : "" ,
32+ "submitting_institution_email" : "" ,
2733 }
2834
29- output_file = ' laboratory_address.json'
30- with open (output_file , 'w' , encoding = ' utf-8' ) as json_file :
35+ output_file = " laboratory_address.json"
36+ with open (output_file , "w" , encoding = " utf-8" ) as json_file :
3137 json .dump (json_dict , json_file , ensure_ascii = False , indent = 4 )
3238
3339print (f"Archivo JSON generado: { output_file } " )
@@ -36,13 +42,13 @@ def to_title_case(value, default="Desconocido"):
3642
3743
3844for index , row in df .iterrows ():
39- hospital_name = to_title_case (row [' NOMBRE' ])
45+ hospital_name = to_title_case (row [" NOMBRE" ])
4046 json_dict_coords [hospital_name ] = {
4147 "geo_loc_latitude" : f"{ row ['Y' ]:.4f} " ,
42- "geo_loc_longitude" : f"{ row ['X' ]:.4f} "
48+ "geo_loc_longitude" : f"{ row ['X' ]:.4f} " ,
4349 }
44- output_file_coords = ' geo_loc_centers.json'
45- with open (output_file_coords , 'w' , encoding = ' utf-8' ) as json_file :
50+ output_file_coords = " geo_loc_centers.json"
51+ with open (output_file_coords , "w" , encoding = " utf-8" ) as json_file :
4652 json .dump (json_dict_coords , json_file , ensure_ascii = False , indent = 4 )
4753
48- print (f"Archivo JSON generado: { output_file_coords } " )
54+ print (f"Archivo JSON generado: { output_file_coords } " )
0 commit comments