← Back to Pandas Course | Chapter 4: Indexing & Selection | Lesson 2 of 7

iloc[] से Selection

iloc integer position से rows और columns select करता है, labels ignore करते हुए।

In this page:

  1. iloc[]
Syntax
python
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[]

python
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. #}
आम गलतियां
  1. iloc को labels pass करना
  2. inclusive slices की उम्मीद करना
  3. एक 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:

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.