I am trying to translate SQL query into python/pandas language, that is set new values to certain subset of pandas data frame, based on condition and inner joining of two tables. The original SQL query is:
UPDATE table1
INNER JOIN table2
ON table1.colA = table2.colB
SET table1.colX = table2.colZ
WHERE table1.colX Is Null;
so far I've got pandas merge
function like mentioned below, but I'm not 100% sure if I get proper results and if the code is pythonic enough.
Current pandas syntax:
table1.loc[table1[colX].isnull()]['colX'] = table1.merge(table2[['colB','colZ']],
how='inner', left_on=['colA'],
right_on=['colB'])['colZ']
Any ideas on how to optimize this?