0
I have the following line of code:
X = data.iloc[:, :-1].values
I can’t understand why :
before the -1
.
0
I have the following line of code:
X = data.iloc[:, :-1].values
I can’t understand why :
before the -1
.
0
When you leave the two points blank, it means you want all the indexes to return.
The first ":" means that it will read from the first to the last line (index).
The "," means the next ":" deals with the columns.
":-1" means that it returns from the first column to the "-1" column, which corresponds to the last column.
Thus, it returns all rows and columns of the dataframe.
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
It means you’re reading backwards from the list, overall I think the code is doing is reversing the positions, what was X1 is assigned with YN and XN, with Y1
– FourZeroFive
just giving more details the ":" means will pick up from "index x até index y", example 1:3, pick from index 1 to 3, in your case it will catch up to the penultimate column
– Lucas Miranda