osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to translate this SQL query to Pandas query


I need to translate this SQL query to Pandas:

SELECT *
     FROM df_dicodes AS di 
     LEFT OUTER JOIN df_2 AS h2
     ON di.Dicode = h2.NM_code AND (datetime(julianday(datetime(di.LastResolDate))) - datetime(julianday(datetime(h2.FechaLectura))) < 180)
     AND ((di.Oficina=h2.Centro AND di.Incidencia=h2.`Num Ticket`)
     OR (di.Incidencia=h2.`Num Ticket` AND (di.Oficina=h2.Centro OR h2.Centro BETWEEN '22015' AND '22025')
     OR (di.Incidencia=h2.`Num Ticket` AND (di.Oficina <> h2.Centro OR h2.Centro BETWEEN '22015' AND '22025')))
     OR (di.Oficina=h2.Centro))
ORDER BY di.Oficina;


df_result = pd.merge(df_dicodes, df_2, how='left', left_on=['Dicode'], right_on=['NM_Code'])

How could I continue this merge?

Thanks!