← Back to Pandas Course | Chapter 6: Data Operations | Lesson 7 of 7

Series को जोड़ना

Series को concat से end to end जोड़ा जा सकता है, या combine_first से एक-दूसरे से fill किया जा सकता है।

In this page:

  1. Combining Series
Syntax
python
combined = pd.concat([s1, s2])
side_by_side = pd.concat([s1, s2], axis=1)

Combining Series

pd.concat([s1, s2]) Series को stack करके एक लंबी Series बनाता है, और axis=1 उन्हें side by side रखकर DataFrame बनाता है। combine_first एक Series के gaps को दूसरी Series से fill करता है। ignore_index=True result को renumber करता है।

Note: axis=1 के साथ concat कई Series से DataFrame बनाने का तेज़ तरीका है।

उदाहरण: Combining Series

python
import pandas as pd
import numpy as np

a = pd.Series([1, 2], index=["x", "y"], name="a")
b = pd.Series([3, 4], index=["y", "z"], name="b")
print(pd.concat([a, b]))
print(pd.concat([a, b], axis=1))
print(pd.Series([1, np.nan, 3]).combine_first(pd.Series([9, 9, 9])))

# Output:
# x    1
# y    2
# y    3
# z    4
# dtype: int64
#      a    b
# x  1.0  NaN
# y  2.0  3.0
# z  NaN  4.0
# 0    1.0
# 1    9.0
# 2    3.0
# dtype: float64
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. concat के बाद duplicate index labels
  2. side-by-side के लिए axis=1 भूल जाना
  3. यह उम्मीद करना कि concat inputs को modify करेगा
चैप्टर सारांश
  • concat Series को stack करता है
  • axis=1 columns बनाता है
  • combine_first gaps fill करता है
  • ignore_index renumber करता है
🔒

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.