簡體   English   中英

從特定的行索引遍歷熊貓數據框

[英]iterate over pandas data frame from a specific row index

我可以使用iterrows函數在pandas數據幀上進行迭代,但是我想知道如何對給定索引的行進行迭代?

我知道有人可以做類似的事情:

index_to_start = 100
current = 0
for _, row in frame.iterrows():
    if current < index_to_start:
        continue
    # Do something 

但是,這看起來有點難看,我想知道是否有更清晰,更直接的方法來做到這一點?

你並不需要額外的if控制

index_to_start = 100
for _, row in frame.iloc[index_to_start:,:].iterrows():
    #do something

此外,在大熊貓中,我們通常不會散行。

你可以在np.where

np.where(df.reset_index().index<100, 'nothing', ' do someting')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM