join() का उपयोग
join index पर merge करने का shortcut है।
In this page:
Syntax
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()
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. #}
आम गलतियां
- overlapping column names से ValueError आना
- यह भूल जाना कि join index का उपयोग करता है
- 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: