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

Comparison Operations करना

कॉलम या पूरे DataFrame की तुलना करने पर True/False जवाब मिलते हैं, जिन्हें आप count या filter कर सकते हैं।

In this page:

  1. Comparison operations
Syntax
python
df["column"] > value
df["column1"] == df["column2"]
(df["column"] > value).sum()

Comparison operations

==, !=, > और < जैसे operators एक जैसी shape के boolean objects return करते हैं। किसी boolean Series को sum करने पर True values की गिनती मिलती है, और mean proportion देता है। eq, ne, gt और lt method forms हैं, और equals पूरे object की equality check करता है।

Note: (df["a"] > 1).mean() 1 से ऊपर की rows का fraction देता है।

उदाहरण: Comparison operations

python
import pandas as pd

df = pd.DataFrame({"a": [1, 5, 9], "b": [2, 5, 7]})
print(df["a"] > df["b"])
print((df["a"] > 3).sum(), (df["a"] > 3).mean().round(2))
print(df.equals(df.copy()))

# Output:
# 0    False
# 1    False
# 2     True
# dtype: bool
# 2 0.67
# True
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. पूरे DataFrames को equality के लिए == से compare करना
  2. अलग-अलग indexes वाली Series को compare करना
  3. यह भूल जाना कि True की गिनती 1 होती है
चैप्टर सारांश
  • Comparisons boolean objects return करते हैं
  • sum True values गिनता है
  • mean proportion देता है
  • equals पूरी equality test करता है
🔒

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.