-1
我正試圖在熊貓數據框中搜索匹配。我發現結果不一致,或者我使用了錯誤的代碼類型。我使用的in命令並不總是一致的。如果我比較值(請參閱示例)它的作品。 in命令有問題嗎?在熊貓數據框中搜索值會返回不一致的結果
代碼示例:
import pandas as pd
report = pd.DataFrame(columns = (['col1','col2']))
report
i = 0
while i < 100:
a = str(i)
addthis = pd.Series({'col1':a,'col2':'AG100'})
report = report.append(addthis,ignore_index=True)
i = i + 1
###this will find a match but not 100 of the time%
i = 0
while i < len(report):
if str(i) in str(report[0:len(report)]):
print('found match on ',i)
else:
print('No match found on ',i)
i = i + 1
###this will find a match 100of the time%
i = 0
while i < len(report):
if str(i) == report.ix[i,0]:
print('found match on ',i)
else:
print('No match found on ',i)
i = i + 1
你應該嘗試使用通過數據框更Python循環方式,如'在report.iterrows)行(',而不是跟蹤櫃檯 – Jezzamon