I would like to do a pandas left merge on a key column but only when the key is not null. In SQL:
select * from tb1l left join tbl2 on tbl1.id=tbl2.id and tbl1.id is not null
How can I do in pandas?
I would like to do a pandas left merge on a key column but only when the key is not null. In SQL:
select * from tb1l left join tbl2 on tbl1.id=tbl2.id and tbl1.id is not null
How can I do in pandas?
I would do it this way:
df = (df_tb1l
.loc[lambda d: d["id"].notnull(), "id"]
.merge(df_tbl2, on=["id"], how="left"]
.merge(df_tb1l, on=["id"], how="right"])