← Back to Pandas Course | Chapter 2: Series | Lesson 4 of 7

Series के Operations

Series पर Arithmetic पहले labels line up करता है, इसलिए values index से match होती हैं, position से नहीं।

In this page:

  1. Series Operations
Syntax
python
s1 + s2
s * scalar
s.sum()

Series Operations

Operators element-wise काम करते हैं और index पर align होते हैं। सिर्फ एक Series में present labels result में NaN देती हैं। उस behaviour को control करने के लिए fill_value वाले add जैसे methods इस्तेमाल करें।

Note: s1.add(s2, fill_value=0) missing labels को 0 treat करता है।

उदाहरण: Series operations

python
import pandas as pd

a = pd.Series([1, 2, 3], index=["x", "y", "z"])
b = pd.Series([10, 20, 30], index=["y", "z", "w"])
print(a + b)
print(a.add(b, fill_value=0))

# Output:
# w     NaN
# x     NaN
# y    12.0
# z    23.0
# dtype: float64
# w    30.0
# x     1.0
# y    12.0
# z    23.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. यह मान लेना कि addition positional है
  2. यह भूल जाना कि unmatched labels के लिए NaN appear होता है
  3. accidentally labels drop करना
चैप्टर सारांश
  • Arithmetic index पर align होता है
  • Unmatched labels NaN बन जाती हैं
  • fill_value वाला add gaps भरता है
  • Scalars broadcast होते हैं
🔒

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.