Expanding Functionality of the .iloc[] Attribute
We will learn some new features that iloc[]
provides. The coolest one is that we can specify indices of both rows and columns. This attribute is similar to .loc[]
, but the last index of the slicing is exclusive.
Look at the example and the relevant output:
data.iloc[1, 2]
- extracts the item located in the dataset's second row and third column. The first index corresponds to the row index, and the second to the column index. Indeed, you can skip one of them;data.iloc[:, 3]
- extracts all values from the rows of the fourth column'IMDb-Rating'
;data.iloc[3, :]
ordata.iloc[3]
- extracts the4th
row and all relevant columns;data.iloc[:2, 1:4]
- extracts the first two rows and column with the indices1
,2
,3
;data.iloc[[2,4],[1,3]]
- extracts the rows with indices2
,4
and columns with the indices1
,3
.
Swipe to start coding
Your task here is just to practice. Output information on the first 50
rows and the columns with indices 1
and 4
.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you explain the difference between iloc[] and loc[] in more detail?
Can you provide more examples of using iloc[] with different index combinations?
What happens if I use negative indices with iloc[]?
Awesome!
Completion rate improved to 3.03
Expanding Functionality of the .iloc[] Attribute
Свайпніть щоб показати меню
We will learn some new features that iloc[]
provides. The coolest one is that we can specify indices of both rows and columns. This attribute is similar to .loc[]
, but the last index of the slicing is exclusive.
Look at the example and the relevant output:
data.iloc[1, 2]
- extracts the item located in the dataset's second row and third column. The first index corresponds to the row index, and the second to the column index. Indeed, you can skip one of them;data.iloc[:, 3]
- extracts all values from the rows of the fourth column'IMDb-Rating'
;data.iloc[3, :]
ordata.iloc[3]
- extracts the4th
row and all relevant columns;data.iloc[:2, 1:4]
- extracts the first two rows and column with the indices1
,2
,3
;data.iloc[[2,4],[1,3]]
- extracts the rows with indices2
,4
and columns with the indices1
,3
.
Swipe to start coding
Your task here is just to practice. Output information on the first 50
rows and the columns with indices 1
and 4
.
Рішення
Дякуємо за ваш відгук!
Awesome!
Completion rate improved to 3.03single