這是我的代碼,其搜索數據幀的一列,並返回,如果要求得到滿足的值:環打破:Python中,熊貓
import pandas as pd
df=pd.read_csv("cl.csv")
count=0
print(len(df.sl_no))
print(len(df.sn_compare))
for i in range(len(df.sn_compare)):
if df.sn_compare[i] in df.sl_no:
print(df.margin[i])
count=count+1
print(count)
輸出:
8258
8258
0.036621541
.
.
.
0.036621541
0.043934426
0.063724333
3770
爲什麼循環在達到3770後停止,理想情況下我希望它搜索所有8259行?
也許是因爲'df.sn_compare'中的'3770'條目在'df.sl_no'中? –
只有滿足condifiton時,纔會提升計數器變量。所以病情滿足3770次。他仍在尋找一切。將count = count + 1放在if語句上方的行中,並檢查結果。 – Secespitus
如果'df.sl_no'中的df.sn_compare [i]只加1'count' –