1

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.

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 1
    Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – sushanth Sep 02 '22 at 08:54
  • Hi @sushanth, this doesn't answer the question. Pandas merge 'ON' will only take a column name. I'm looking for if we can pass on a value. Ex (pd.merge(TAL,TNA, on=['TAL.TaskId'=123],how='left). I know the syntax is not correct, but looking for something on these lines. – Deluxplanet345 Sep 02 '22 at 09:18

1 Answers1

0

Using pandas, you could do:

TAL[TAL.Id == TNAA.Id].merge(TNA[TNA.TaskId == 123],
    left_on='Id',
    right_on='TaskId',
    how='left')
vtasca
  • 1,660
  • 11
  • 17