import duckdb, csv c=duckdb.connect() ok=0 for r in csv.DictReader(open('/w/salidas/60_muestra_cotejo.csv')): v=c.execute("select coalesce(gasto_cap2,0)+coalesce(gasto_cap6,0), con_liquidacion, liquidacion_avance from '/d/aggregations_20261123/presupuestos/municipios_gasto_anio.parquet' where municipio_ine=? and anio=?",[r['ine'],int(r['anio'])]).fetchone() Lt=float(v[0]) if v and v[1] else 0.0; o=abs(Lt-float(r['L']))<=0.01; ok+=o print(r['codigo'],r['anio'],'L_tabla',round(Lt,2),'L_impl1',r['L'],'ok' if o else 'NO', '(sin liquidación)' if not (v and v[1]) else '') print('cotejo L',ok,'/ 20') print('--- por CCAA (código PMP CC), 2019-2024: cc, N, con órgano por código, A_cod/A_web, mediana A_cod/P, mediana A_web/P') for x in c.execute("""select substr(codigo,1,2) cc, count(*), round(avg(org_cod::int),3), round(sum(A)/nullif(sum(Aw),0),3), round(median(R_AP),4), round(median(Aw/P),4) from '/w/salidas/30_ayto_anio_impl1.parquet' where anio<=2024 group by 1 order by 1""").fetchall(): print(x) print('--- sin padrón:', c.execute("select count(distinct ine), list(distinct ine)[:10] from '/w/salidas/30_ayto_anio_impl1.parquet' where pob is null").fetchall())