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

Time:02-22

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.

CodePudding user response:

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

CodePudding user response:

You can do

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

CodePudding user response:

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

df.iloc[-1, 1]

  • Related