Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select rows except last row of one column?

Tags:

python

pandas

I'd like to select one column only but all the rows except last row.

If I did it like below, the result is empty.

a = data_vaf.loc[:-1, 'Area']
like image 977
roudan Avatar asked Oct 19 '25 09:10

roudan


1 Answers

loc:location
iloc:index location.

They just can't operate implicitly.

Therefore we exclude last raw by iloc then select the column Area As shown by the comment from @ThePyGuy

data_vaf.iloc[:-1]['Area']

Here's the structure of iloc[row, column]

And iloc[row] do the same thing as iloc[row,:]
df.iloc[:-1] do the same thing as df[:-1]

like image 67
Baron Legendre Avatar answered Oct 21 '25 22:10

Baron Legendre