Series में Slicing
Slicing items की एक range लेती है; positional slices end exclude करती हैं जबकि label slices इसे include करती हैं।
In this page:
Syntax
s.iloc[start:stop]
s.loc["label1":"label2"]
Series Slicing
s.iloc[1:3] जैसी Positional slices Python rules follow करती हैं और end exclude करती हैं। s.loc["a":"c"] जैसी Label slices दोनों ends include करती हैं। आप s[::2] जैसे steps भी इस्तेमाल कर सकते हैं।
Note:
यह label-inclusive rule एक famous Pandas gotcha है।
उदाहरण: Series slicing
import pandas as pd
s = pd.Series([1, 2, 3, 4, 5], index=list("abcde"))
print(s.iloc[1:3])
print(s.loc["b":"d"])
print(s[::2])
# Output:
# b 2
# c 3
# dtype: int64
# b 2
# c 3
# d 4
# dtype: int64
# a 1
# c 3
# e 5
# 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 slices end exclude करेंगी
- गलत indexer type से slice करना
- यह भूल जाना कि एक slice एक view हो सकती है
चैप्टर सारांश
- iloc slices end exclude करती हैं
- loc slices end include करती हैं
- Steps allowed हैं
- Slices index labels रखती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: