How to perform SQL Join with 2 conditions in Python?

Viewed 40

I have a SQL Query which joins two tables:

SQL => select * from TAL left join TNA on TNA.TaskId = 123 and TAL.Id = TNAA.Id

In Python, I've read the tables from Excel and now I want to write the same logic. Is there any way through this can be achieved?

Note: pandasql library works and does the same job. However, I am looking for a solution which can be done without writing code in SQL format.

1 Answers

Using pandas, you could do:

TAL[TAL.Id == TNAA.Id].merge(TNA[TNA.TaskId == 123],
    left_on='Id',
    right_on='TaskId',
    how='left')
Related