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

join() का उपयोग

join index पर merge करने का shortcut है।

In this page:

  1. join()
Syntax
python
joined = df1.join(df2)
joined = df1.join(df2, on="column", how="left")

join()

df1.join(df2) rows को index labels के अनुसार align करता है और default रूप से left join करता है। df1 के column को df2 के index के खिलाफ join करने के लिए on="col" का उपयोग करें। यह ऐसी स्थितियों के लिए उपयुक्त है जहां एक table पहले से key पर indexed हो।

Note: column names overlap होने पर lsuffix और rsuffix का उपयोग करें।

उदाहरण: join()

python
import pandas as pd

a = pd.DataFrame({"name": ["Ann", "Bob"]}, index=[1, 2])
b = pd.DataFrame({"score": [90, 80]}, index=[2, 3])
print(a.join(b))
print(a.join(b, how="inner"))

# Output:
#   name  score
# 1  Ann    NaN
# 2  Bob   90.0
#   name  score
# 2  Bob     90
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. overlapping column names से ValueError आना
  2. यह भूल जाना कि join index का उपयोग करता है
  3. default रूप से inner join की उम्मीद करना
चैप्टर सारांश
  • join index पर merge करता है
  • Default left join है
  • on= left table के किसी column का उपयोग करता है
  • Overlapping names को suffixes चाहिए
🔒

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.