iloc[] से Selection
iloc integer position से rows और columns select करता है, labels ignore करते हुए।
In this page:
Syntax
df.iloc[row_positions, column_positions]
df.iloc[0:3, 0:2]
iloc[]
df.iloc[row_positions, column_positions] NumPy indexing जैसा काम करता है, 0 से शुरू होते हुए और एक slice का end exclude करते हुए। यह integers, lists, और slices accept करता है, लेकिन Series की label-based masks नहीं।
जब आप position की परवाह करें, जैसे पहली या last rows, इसे इस्तेमाल करें।
Note:
df.iloc[-1] last row return करता है।
उदाहरण: iloc[]
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
print(df.iloc[0])
print(df.iloc[1:, :2])
print(df.iloc[-1, 2])
# Output:
# a 1
# b 4
# c 7
# Name: 0, dtype: int64
# a b
# 1 2 5
# 2 3 6
# 9
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. #}
आम गलतियां
- iloc को labels pass करना
- inclusive slices की उम्मीद करना
- एक plain boolean array की बजाय एक boolean Series इस्तेमाल करना
चैप्टर सारांश
- iloc position-based है
- Slices end exclude करती हैं
- Negative positions काम करते हैं
- Integers, lists, और slices accept करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: