Chorlton2080
Chorlton2080

Reputation: 111

How can I obtain a cell value from the last line of a list?

I'm struggling to figure out how, using Pandas, to obtain the last value in the second column of a list which is updating regularly (i.e. an every increasing list over time) and assign that to a value.

                          1           2
15  21/02/2022 18:07:40  38055.3966
16  21/02/2022 18:07:49  38055.3966
17  21/02/2022 18:08:58  38039.6075
18  21/02/2022 18:09:47  38087.6340
19  21/02/2022 18:10:34  38036.3207

Can anyone offer any advice? Note that Index "19" may be "20"..."21"...etc as the list updates.

Upvotes: 0

Views: 33

Answers (3)

Victor Bayona
Victor Bayona

Reputation: 21

You can obtain the last row using index negative notation with iloc and positive for column.

df.iloc[-1, 1]

Upvotes: 0

BENY
BENY

Reputation: 323226

You can do

df.iloc[-1,1] = some value

Upvotes: 1

Ben Grossmann
Ben Grossmann

Reputation: 4772

One approach is to use iloc. For example, df.iloc[-2,1] gives the second to last entry of the second column.

Upvotes: 1

Related Questions