你好,我有两个数据帧。一个是master db1(它有许多行),第二个是sourcetarget(它较小)。我想查看db1sourcetarget中的所有单词,如果匹配,我将创建一个新的布尔列(0,1)。我试过这个代码(复杂度很高),但我总是得到0。怎么了
start_time = time.time()
compt=0
for i in db1.clean_nomComplet:
for j in sourcetarget.sourcetarget:
res0 = i.find(j)
if res0 >= 0:
db1['top'] = 1
else:
db1['top'] = 0
compt+=1
print(compt/len(db1)*100,end="\r")
if compt%50000 == 0:
print("../data_out/sauve"+str(compt)+'.csv')
db1.to_csv('../data_out/sauve'+str(compt)+'.csv', encoding='utf-8-sig')
print("--- %s seconds ---" % (time.time() - start_time))```
我发现做这种比较最好的方法是:
脚本上的问题是更改整个列的值。您应该使用:
相关问题 更多 >
编程相关推荐