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

Viewed 3232

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']
3 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]

There are multiple ways to do this as addressed in the comments using iloc.

df['col'].iloc[:-1]

Then we just drop the last row

out = data_vaf.drop(data_vaf.index[-1])['Area']
Related