← Back to Pandas Course | Chapter 8: Merging & Joining | Lesson 2 of 7

merge() से Inner Join

merge किसी key column में values मिलाकर दो tables को जोड़ता है; inner join सिर्फ वही rows रखता है जो दोनों में मिलें।

In this page:

  1. merge() inner join
Syntax
python
merged = pd.merge(left, right, on="key_column")

merge() inner join

pd.merge(left, right, on="key") SQL JOIN का Pandas version है। default how="inner" सिर्फ वही keys रखता है जो दोनों tables में हों। अगर key names अलग हों, तो left_on और right_on का उपयोग करें।

Note: अनपेक्षित duplicate keys पकड़ने के लिए validate="one_to_one" का उपयोग करें।

उदाहरण: merge() inner join

python
import pandas as pd

emp = pd.DataFrame({"emp_id": [1, 2, 3], "name": ["Ann", "Bob", "Cy"], "dept_id": [10, 20, 30]})
dept = pd.DataFrame({"dept_id": [10, 20, 40], "dept": ["Sales", "Tech", "HR"]})
print(pd.merge(emp, dept, on="dept_id"))

# Output:
#    emp_id name  dept_id   dept
# 0       1  Ann       10  Sales
# 1       2  Bob       20   Tech
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह realize किए बिना rows खोना कि inner join unmatched keys को drop कर देता है
  2. अलग-अलग dtypes वाली keys पर merge करना
  3. duplicate keys से rows का अनपेक्षित गुणा होना
चैप्टर सारांश
  • merge key columns पर match करता है
  • Default inner join है
  • left_on और right_on अलग नामों को handle करते हैं
  • Duplicate keys rows को गुणा करती हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.