Выберите строку серии или фрейм данных по заданному целочисленному индексу
Dataframe.iloc [] используется для выбора строки серии / кадра данных по заданному целочисленному индексу. Создадим фрейм данных:
Code:
Python3
# import pandas libraryimport pandas as pd # Create the dataframe df = pd.DataFrame({"ID": ["114", "345", "157788", "5626"], "Product": ["shirt", "trousers", "tie", "belt"], "Price": [1200, 1500, 600, 352], "Color": ["White","Black", "Red", "Brown"], "Discount": [10, 10, 10, 10]}) # Show the dataframedf |
Выход:

Now, Selecting a row of series/dataframe by a given integer index:
Example 1: Selecting the first row only.
Python3
# select first row # from the dataframedf.iloc[0] |
Выход:

Example 2: Selecting 0,1,2 rows.
Python3
# select 0, 1, 2 rows#from the dataframedf.iloc[0 : 3] |
Выход:

Example 3: Selecting rows from 0 to 2 and columns 0 to 1.
Python3
# selecting rows from 0 to# 2 and columns 0 to 1df.iloc[0 : 3, 0 : 2] |
Выход:

Example 4: Selecting all rows and columns from 0 to 3.
Python3
# selecting all rows and # columns from 0 to 3df.iloc[ : , 0 : 4] |
Выход:

Example 5: Selecting all rows and 2nd column.
Python3
# selecting all rows and # 3rd columndf.iloc[ : , 2] |
Выход:

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.