我知道这个错误是很常见的,我试过一些解决方法,我查了一下,仍然不明白是什么错了。我想是因为row和row1的可变形式,但我想不出来
我想做什么? 我有两个数据帧。我需要遍历第一个1的行,对于第一个1的每一行,遍历第二个1并检查某些列的单元格值。 我的代码和不同的尝试:
a=0
b=0
for row in Correction.iterrows():
b+=1
for row1 in dataframe.iterrows():
c+=1
a=0
print('Handling correction '+str(b)+' and deal '+str(c))
if (Correction.loc[row,['BO Branch Code']]==dataframe.loc[row1,['wings Branch']] and Correction.loc[row,['Profit Center']]==dataframe.loc[row1,['Profit Center']] and Correction.loc[row,['Back Office']]==dataframe.loc[row1,['Back Office']]
and Correction.loc[row,['BO System Code']]==dataframe.loc[row1,['BO System Code']]):
我也试过了
a=0
b=0
for row in Correction.iterrows():
b+=1
for row1 in dataframe.iterrows():
c+=1
a=0
print('Handling correction '+str(b)+' and deal '+str(c))
if (Correction[row]['BO Branch Code']==dataframe[row1]['wings Branch'] and Correction[row]['Profit Center']==dataframe[row1]['Profit Center'] and Correction[row]['Back Office']==dataframe[row1]['Back Office']
and Correction[row]['BO System Code']==dataframe[row1]['BO System Code']):
以及
a=0
b=0
for row in Correction.iterrows():
b+=1
for row1 in dataframe.iterrows():
c+=1
a=0
print('Handling correction '+str(b)+' and deal '+str(c))
if (Correction.loc[row,['BO Branch Code']]==dataframe[row1,['wings Branch']] and Correction[row,['Profit Center']]==dataframe[row1,['Profit Center']] and Correction[row,['Back Office']]==dataframe[row1,['Back Office']]
and Correction[row,['BO System Code']]==dataframe[row1,['BO System Code']]):
我认为你的df迭代错误
引用如何迭代数据帧:https://github.com/vi3k6i5/pandas_basics/blob/master/2.A%20Iterate%20over%20a%20dataframe.ipynb
我为索引方法和迭代器方法计时。结果如下:
简单地说它比你的方法快得多。
关于在数据帧What is the most efficient way to loop through dataframes with pandas?上循环的好方法的参考
我通过改变我的for循环找到了一种方法 现在我的代码是:
相关问题 更多 >
编程相关推荐