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

Boolean Series क्या है

एक Series compare करना प्रति item True/False देता है, और वह mask Series filter कर सकता है।

In this page:

  1. Boolean Series
Syntax
python
mask = s > value
s[mask]
s[(s > a) & (s < b)]

Boolean Series

s > 10 जैसा एक comparison same index वाला एक boolean Series return करता है। सिर्फ True rows रखने के लिए इसे brackets के अंदर pass करें। & (and), | (or), और ~ (not) के साथ combine करें, parentheses इस्तेमाल करते हुए।

Note: isin() एक list में membership test करता है, और between() एक range test करता है।

उदाहरण: Boolean Series

python
import pandas as pd

s = pd.Series([5, 12, 18, 3, 25])
mask = s > 10
print(mask)
print(s[mask])
print(s[s.between(4, 20)])

# Output:
# 0    False
# 1     True
# 2     True
# 3    False
# 4     True
# dtype: bool
# 1    12
# 2    18
# 4    25
# dtype: int64
# 0     5
# 1    12
# 2    18
# dtype: int64
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. & / | की बजाय and / or इस्तेमाल करना
  2. parentheses भूल जाना
  3. mask को filtered result से confuse करना
चैप्टर सारांश
  • Comparisons boolean Series देते हैं
  • एक mask वाले brackets filter करते हैं
  • parentheses के साथ & | ~ इस्तेमाल करें
  • isin और between handy हैं
🔒

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.