我可以使用该函数遍历 pandas 数据框,iterrows但我想知道如何遍历给定索引中的行?我知道可以做类似的事情:index_to_start = 100current = 0for _, row in frame.iterrows(): if current < index_to_start: continue # Do something 但是,这似乎有点难看,我想知道是否有更清晰、更直接的方法来做到这一点?
1 回答

ABOUTYOU
TA贡献1812条经验 获得超5个赞
您不需要额外if的控制
index_to_start = 100
for _, row in frame.iloc[index_to_start:,:].iterrows():
#do something
此外,在 pandas 中,我们通常不会迭代。
你可以做np.where
np.where(df.reset_index().index<100, 'nothing', ' do someting')
添加回答
举报
0/150
提交
取消