update file

This commit is contained in:
Colas Geier 2024-07-26 11:48:13 +02:00
parent 9aabd4d543
commit 37ccf6d3a8

View File

@ -20,26 +20,42 @@ def get_status(lst):
t.nom_valide,
t.lb_nom,
--s.*
s.rq_statut,
s.code_statut,
s.cd_type_statut,
s.label_statut
FROM taxonomie.v_taxref_all_listes t
s.label_statut,
s.full_citation,
s.doc_url
FROM taxonomie.taxref t
JOIN taxonomie.v_bdc_status s USING (cd_nom)
WHERE t.cd_nom IN {cd_nom}
;""".format(cd_nom = tuple(lst))
return pd.read_sql_query(sql,con_gn)
dict_dep = {
'38':'Isère',
'42':'Loire',
'07':'Ardèche',
'26':'Drôme',
}
if __name__ == "__main__":
PATH = '/media/colas/Disk2/tmp/NICO'
file = 'MAIR_FAUNE&FLORE_PG2024_V0.xlsx'
sheet = 'MAIR_FLORE'
PATH = '/media/colas/SRV/FICHIERS/SITES/SITES GERES/ROLA_ROLANDE-MAUPAS/ROLA_PPI/ROLA_2025-2034_PG/donneesnaturalistes'
file = 'liste sp_ROLA.xlsx'
sheet = 'liste sp'
# Liste des CD_NOM en entrée
taxlist = pd.read_excel(os.path.join(PATH,file),sheet,usecols=['cd_nom'],header=1)
df = get_status(taxlist.cd_nom.astype(str))
cd_col = 'cd_ref'
taxlist = pd.read_excel(os.path.join(PATH,file),sheet,usecols=[cd_col],header=0)
tab_sp = pd.read_excel(os.path.join(PATH,file),sheet,index_col=cd_col)
df = get_status(taxlist[cd_col].astype(str))
for c in ['cd_ref','cd_nom','lb_nom']:
if c in tab_sp.columns:
# if 'cd_nom' not in df.columns and c == 'cd_ref': continue
tab_sp.drop(c,axis=1,inplace=True)
# df.to_csv('/media/colas/SRV/FICHIERS/TRANSFERTS-EQUIPE/LC/BOCA_CD_NOM_STATUS.csv')
@ -57,6 +73,8 @@ if __name__ == "__main__":
pivot['DH'] = [','.join(x) if (x is not np.NaN) and (len(x)==2) else x for x in pivot['DH']]
pivot.DH.replace({'CDH':''},regex=True,inplace=True)
pivot = tab_sp.merge(pivot,on=[cd_col],how='left')
pivlib = pd.pivot_table(
df,
@ -71,12 +89,13 @@ if __name__ == "__main__":
pivlib['DH'] = [','.join(x) if (x is not np.NaN) and (len(x)==2) else x for x in pivlib['DH']]
pivlib.DH.replace({'CDH':''},regex=True,inplace=True)
pivlib = tab_sp.merge(pivlib,on=[cd_col],how='left')
print('INIT writer')
NAME_OUT = os.path.join(PATH,sheet+'_status.xlsx')
with pd.ExcelWriter(NAME_OUT) as writer:
df.to_excel(
writer,sheet_name='v_bdc_status'
writer,sheet_name='v_bdc_status',index=False
)
# writer.save()
print('v_bdc_status OK !')