Home › Interview Questions › Write code to join the employee DataFrame with the…

Write code to join the employee DataFrame with the department DataFrame, include the department commission, and write the result to a CSV file.

🟢 Easy Coding Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

python
import pandas as pd
# Load data
emp = pd.read_csv('employees.csv')
dep = pd.read_csv('departments.csv')
# Merge on department_id and bring commission
merged = pd.merge(emp, dep[['department_id', 'commission']], on='department_id', how='left')
# Write to CSV
merged.to_csv('employees_with_commission.csv', index=False)

The merge is an inner join on department_id; the commission column is added from the departments DataFrame. Complexity is linear in the size of the input tables.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500