Python 将数据帧分成块

Jav*_*rre 2 python pandas

我有 1 列 df,有 37365 行。我需要将其分成如下所示的块:

df[0:2499]
df[2500:4999]
df[5000:7499]
...
df[32500:34999]
df[35000:37364]
Run Code Online (Sandbox Code Playgroud)

这个想法是在如下循环中使用它(process_operation 不适用于大于 2500 行的 dfs)

while chunk <len(df):
    process_operation(df[lower:upper])
Run Code Online (Sandbox Code Playgroud)

编辑:我将有不同的数据帧作为输入。其中一些小于 2500。捕获这些的最佳方法是什么?

Ej: df[0:1234] because 1234<2500
Run Code Online (Sandbox Code Playgroud)

Ser*_*sta 5

这里的功能range就足够了:

for start in range(0, len(df), 2500):
    process_operation(df[start:start+2500])
Run Code Online (Sandbox Code Playgroud)