首页 > 解决方案 > 从特定行开始迭代数据框

问题描述

我的数据框:

                  dt_object     price
0       1990-01-01 00:00:00  1.050067
1       1990-01-01 00:05:00  1.049700
2       1990-01-01 00:10:00  1.049933
3       1990-01-01 00:15:00  1.049733
4       1990-01-01 00:20:00  1.050033

我使用它迭代它

for index, row in df.iterrows():
    if index >= 9000000:
       #do_the_job

数据文件非常大。我需要从索引 9000000 开始迭代。我可以从这个索引开始迭代一次吗?从 0 到 9000000 的校验需要很长时间才能通过。
我无法将数据从 0 截断到 9000000,因为我正在使用过去的数据进行计算。对于当前行,结果是根据过去的值计算的。

标签: pythonpandas

解决方案


您可以对 DataFrame 进行切片:

for index, row in df.iloc[9000000:].iterrows():
    pass

推荐阅读