Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how how iloc[:,1:] works ? can any one explain [:,1:] params

What is the meaning of below lines., especially confused about how iloc[:,1:] is working ? and also data[:,:1]

data = np.asarray(train_df_mv_norm.iloc[:,1:])
X, Y = data[:,1:],data[:,:1]

Here train_df_mv_norm is a dataframe --

one

like image 859
Abhishek Avatar asked Oct 20 '25 04:10

Abhishek


1 Answers

Definition: pandas iloc

.iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array.

For example:

df.iloc[:3] # slice your object, i.e. first three rows of your dataframe
df.iloc[0:3] # same
df.iloc[0, 1] # index both axis. Select the element from the first row, second column.
df.iloc[:, 0:5] # first five columns of data frame with all rows

So, your dataframe train_df_mv_norm.iloc[:,1:] will select all rows but your first column will be excluded.

Note that:

  • df.iloc[:,:1] select all rows and columns from 0 (included) to 1 (excluded).
  • df.iloc[:,1:] select all rows and columns, but exclude column 1.
like image 61
KeyMaker00 Avatar answered Oct 25 '25 00:10

KeyMaker00