Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära The `iloc` Property | Fetching Data from DataFrames
Pandas: First Steps
course content

Kursinnehåll

Pandas: First Steps

Pandas: First Steps

1. Getting Started
2. Basics of Dataframes
3. Fetching Data from DataFrames

book
The `iloc` Property

The iloc property in Pandas allows us to access specific parts of a DataFrame using numerical positions.

You can use iloc to access:

  • A single element;

  • A single row;

  • A single column;

  • A range of rows;

  • A range of columns;

  • A range of rows and columns.

General Syntax

js

You can also slice:

python

Example

12345678910111213141516171819202122232425
import pandas as pd df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie', 'Daisy'], 'Age': [25, 30, 35, 28], 'City': ['New York', 'Paris', 'London', 'Berlin'] }) # Single element print('>> Single Element:\n', df.iloc[1, 2]) # Single row print('\n>> Single Row:\n', df.iloc[2]) # Single column print('\n>> Single Column:\n', df.iloc[:, 1]) # Range of rows print('\n>> Range of Rows:\n', df.iloc[1:3]) # Range of columns print('\n>> Range of Columns:\n', df.iloc[:, 0:2]) # Range of rows and columns print('\n>> Range of Rows & Columns:\n', df.iloc[1:3, 0:2])
copy
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 10

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

Pandas: First Steps

Pandas: First Steps

1. Getting Started
2. Basics of Dataframes
3. Fetching Data from DataFrames

book
The `iloc` Property

The iloc property in Pandas allows us to access specific parts of a DataFrame using numerical positions.

You can use iloc to access:

  • A single element;

  • A single row;

  • A single column;

  • A range of rows;

  • A range of columns;

  • A range of rows and columns.

General Syntax

js

You can also slice:

python

Example

12345678910111213141516171819202122232425
import pandas as pd df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie', 'Daisy'], 'Age': [25, 30, 35, 28], 'City': ['New York', 'Paris', 'London', 'Berlin'] }) # Single element print('>> Single Element:\n', df.iloc[1, 2]) # Single row print('\n>> Single Row:\n', df.iloc[2]) # Single column print('\n>> Single Column:\n', df.iloc[:, 1]) # Range of rows print('\n>> Range of Rows:\n', df.iloc[1:3]) # Range of columns print('\n>> Range of Columns:\n', df.iloc[:, 0:2]) # Range of rows and columns print('\n>> Range of Rows & Columns:\n', df.iloc[1:3, 0:2])
copy
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 10
Vi beklagar att något gick fel. Vad hände?
some-alt