-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