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

Arithmetic Operations करना

Columns और DataFrames पर Arithmetic element-wise है और labels पर align होता है।

In this page:

  1. Arithmetic Operations
Syntax
python
df["column1"] + df["column2"]
df["column"] * scalar
df["column1"] / df["column2"]

Arithmetic Operations

+, -, *, /, और ** columns, scalars, और पूरे DataFrames के बीच काम करते हैं। Operations index और column labels पर align होते हैं, जहाँ labels match न करें वहाँ NaN देते हुए। add, sub, mul, और div जैसे methods fill_value और axis control offer करते हैं।

Note: Rows को proportions में convert करने के लिए df.div(df.sum(axis=1), axis=0) इस्तेमाल करें।

उदाहरण: Arithmetic operations

python
import pandas as pd

df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
print(df * 10)
print(df["a"] + df["b"])
print(df.div(df.sum(axis=1), axis=0))

# Output:
#     a   b
# 0  10  30
# 1  20  40
# 0    4
# 1    6
# dtype: int64
#           a         b
# 0  0.250000  0.750000
# 1  0.333333  0.666667
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. Positional alignment की उम्मीद करना
  2. mismatched labels से NaN ignore करना
  3. axis argument भूल जाना
चैप्टर सारांश
  • Operators element-wise हैं
  • Alignment labels इस्तेमाल करता है
  • add, sub, mul, div fill_value accept करते हैं
  • axis direction चुनता है
🔒

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.