我可以检查熊猫数据帧索引是否结束?

use*_*519 3 python dataframe python-3.x pandas

我使用 while 循环在数据框中显示数据

while True:
    last_id = get_last_id()
    res = df.iloc[last_id + 1]
Run Code Online (Sandbox Code Playgroud)

当 last_id 数据结束并仍然使用 last_id + 1 时显示错误

IndexError: single positional indexer is out-of-bounds
Run Code Online (Sandbox Code Playgroud)

我可以检查数据帧索引中是否没有 last_id + 1 然后不显示任何内容吗?

U10*_*ard 7

为什么不+1从最后一行删除:

while True:
    last_id = get_last_id()
    res = df.iloc[last_id]
Run Code Online (Sandbox Code Playgroud)