📜  pandas 循环遍历大块行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:11.699000             🧑  作者: Mango

代码示例1
# credit to Stack Overflow user in the source link
import numpy as np
import pandas as pd

data = pd.DataFrame(np.random.rand(10, 3))
for chunk in np.array_split(data, 5):
  # this assert may not be needed depending on your application
  # left here anyway because it is in the original answer
  assert len(chunk) == len(data) / 5, "This assert may fail for the last chunk if data lenght isn't divisible by 5"
  # do your stuff with each chunk