带有迭代的Pandas DataFrame切片 [英] Pandas DataFrame slicing with iteration

查看:99
本文介绍了带有迭代的Pandas DataFrame切片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对具有多个切片索引的切片DataFrame执行一些操作.模式是df.iloc [0:24],df.iloc [24:48],df.iloc [48:72],依此类推,如步骤24所示.我如何迭代它,而不必每次都手动设置它.更类似于df.iloc [x:z],每次迭代x = 0,z = 24,下一次迭代有24步,x将是24,z = 48,依此类推. 提前致谢, 赫里斯托.

I would like to perform some action on sliced DataFrame with multiple slice indexes. The pattern is df.iloc[0:24] , df.iloc[24:48], df.iloc[48:72] and so on with step 24 as you get it. How I can iterate it without to set it manually every time. More like df.iloc[x:z] and each iteration x=0, z=24 and next iteration with 24 step, x will be 24 and z=48 and so on. Thanks in advance, Hristo.

推荐答案

for 循环迭代

for i in range(0, len(df), 24):
    slc = df.iloc[i : i + 24]


groupby


groupby

df.groupby(df.index // 24 * 24).apply(your_function)

这篇关于带有迭代的Pandas DataFrame切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆