Series में Indexing
label या position से एक Series से single values pick करें।
In this page:
Syntax
s["label"]
s.loc["label"]
s.iloc[position]
Series Indexing
एक label के साथ square brackets इस्तेमाल करें, s["b"], या labels के लिए .loc और integer positions के लिए .iloc। .loc और .iloc के साथ explicit होना confusion से बचाता है जब labels खुद integers हों। labels की एक list एक छोटा Series return करती है।
Note:
Integer labels के साथ, s[0] का मतलब शायद एक label हो, position नहीं; safe रहने के लिए iloc इस्तेमाल करें।
उदाहरण: Series indexing
import pandas as pd
s = pd.Series([10, 20, 30], index=["a", "b", "c"])
print(s["b"])
print(s.loc["c"], s.iloc[0])
print(s[["a", "c"]])
# Output:
# 20
# 30 10
# a 10
# c 30
# 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. #}
आम गलतियां
- label-based और position-based access mix up करना
- एक missing label request करना और KeyError पाना
- एक integer-labelled index पर s[0] इस्तेमाल करना
चैप्टर सारांश
- Brackets और loc labels इस्तेमाल करते हैं
- iloc positions इस्तेमाल करता है
- labels की एक list एक Series return करती है
- Missing labels KeyError raise करती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: