concat() का उपयोग
concat DataFrames को एक-दूसरे के ऊपर या साथ-साथ stack करता है।
In this page:
Syntax
pd.concat([df1, df2])
pd.concat([df1, df2], axis=1)
concat()
pd.concat([df1, df2]) rows जोड़ता है (axis=0), और axis=1 उन्हें index पर aligned करके side by side रखता है। ignore_index=True एक साफ़ index फिर से बनाता है। हर block के source को label करने के लिए keys का उपयोग करें।
Note:
loop में concat धीमा होता है; DataFrames को एक list में collect करें और एक बार concat call करें।
उदाहरण: concat()
import pandas as pd
a = pd.DataFrame({"id": [1, 2], "v": ["x", "y"]})
b = pd.DataFrame({"id": [3], "v": ["z"]})
print(pd.concat([a, b], ignore_index=True))
print(pd.concat([a, b], keys=["first", "second"]))
# Output:
# id v
# 0 1 x
# 1 2 y
# 2 3 z
# id v
# first 0 1 x
# 1 2 y
# second 0 3 z
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. #}
आम गलतियां
- stacking के बाद duplicate index labels
- loop के अंदर बार-बार concat call करना
- mismatched columns जो NaN बनाते हैं
चैप्टर सारांश
- axis=0 rows को stack करता है
- axis=1 columns को जोड़ता है
- ignore_index renumber करता है
- Mismatched columns NaN बन जाते हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: