Dear Sir
Please review all my dataframes and queries. I require an inner join of three dataframes similar to the Oracle SQL query sample provided below. How can I achieve this type of join in pandas? I would appreciate your guidance.
Import pandas as pd
Employees (Parent table)
employees = pd.DataFrame({
‘emp_id’: [1, 2, 3],
‘name’: [‘Alice’, ‘Bob’, ‘Charlie’]
})
Departments (Child table - FK is emp_id)
departments = pd.DataFrame({
‘dept_id’: [101, 102, 103],
‘emp_id’: [2, 3, 4], # 4 doesn’t exist in employees
‘item_id’: [2, 3, 4], # 4 doesn’t exist in employees
‘dept_name’: [‘HR’, ‘IT’, ‘Finance’]
})
itemtab = pd.DataFrame({
‘dept_id’: [101, 102, 103,‘’,‘’,‘’],
‘item_id’: [1,2, 3, 4,5,6], # 4 doesn’t exist in employees
‘item_name’: [‘computer’, ‘car’, ‘bus’,‘home’, ‘flate’, ‘treain’]
})
SQL equivalent:
need this oracle this type of query result SELECT * FROM employees, departments, itemtab where employees.emp_id = departments.emp_id and departments.item_id = itemtab.item_id
i try this code in python but it give me error
result = pd.merge(employees, departments, itemtab,left_on=[‘emp_id’,‘item_id’], right_on=[‘emp_id’,‘item_id’], how=‘inner’)
print(result)