Python Forum
SQL select join operation in python(Select.. join)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQL select join operation in python(Select.. join)
I have data set called Account_universe
001AAD 638400
002ADF 638402
003AAS 638902
004AGF 123480
005AQA 987650

Next data set Alt_Account_univ
001AAD 10000 confd
002ADF 10001 Non confd
003AAS 10002 Non confd
004AGF 10003 Non confd
005AQA 10004 confd

In sql I will do like

from Account_universe a
left join Alt_Account_univ b on b.acct_id = a.acct_id

In pandas I will do like

df_a = Account_universe
df_b= Alt_Account_univ
df1 =df_a.merge(df_b[['ACCT_ID','ALT_ID']],on='ACCT_ID',how='left')
What I have tried in python without(pandas)

set(df_a) & set(df_b)
Here how to join on specific columns and I have to write only a.ACCT_ID,b.ALT_ID,a.ZIP_CODE these columns in another list. I am aware this set will act like A intersect B any other possible ways to do this operation?.

Thanks in Advance!!
If I understand you it would be something along the lines of
## using you pseudo-code
Select ACCT_ID, ZIP_CODE from a 
select ALT_ID from b 

for ctr, row in enumerate(recs_a):  ## assumes a and b are the same length
    combined_list.append([row[0], recs_b[ctr], row[1]]) 

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error using mariadb select query with form in python? shams 2 123 Jul-29-2021, 12:30 PM
Last Post: shams
  ''.join and start:stop:step notation for lists ringgeest11 1 435 Apr-08-2021, 04:29 PM
Last Post: BashBedlam
  Select data between DW felmback 2 435 Mar-21-2021, 01:49 PM
Last Post: ibreeden
  Subprocesses not opening File Select Dialog teut 2 421 Feb-22-2021, 08:07 PM
Last Post: teut
  os.path.join - errors out tester_V 4 587 Nov-29-2020, 08:57 AM
Last Post: DeaD_EyE
  The difference between os.path.join( and os.sep.join( Pedroski55 2 1,086 Nov-17-2020, 08:38 AM
Last Post: Pedroski55
  Select a value from Dataframe mfkzolo 2 532 Nov-15-2020, 03:09 PM
Last Post: puneethr12
  os.path.join qmfoam 2 544 Nov-08-2020, 04:03 PM
Last Post: qmfoam
  Multi Select from SQL tehzeebahmed 6 770 Oct-19-2020, 12:35 AM
Last Post: scidam
  Select the other of 2 items in a list Clunk_Head 7 1,017 Sep-01-2020, 05:27 PM
Last Post: Clunk_Head

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020