如果在csv文件熊猫中找到字符串匹配项,则打印行

时间:2019-03-04 09:56:54

标签: python pandas

我为主题任务编写了以下代码。 我认为循环运行正常,但print命令未显示任何输出。 您能看到并帮我解决吗?

import pandas as pd
df = pd.read_csv('file1.csv') # read 1st file to get strings from a column 
da = pd.read_csv("file2.csv",encoding = 'unicode_escape') #read 2nd file to search the string in
a =393
b = 0
c = 712
d = 0
while b<a: 
    D = df.iloc[b,0] # get string in bth row of 1st column of 1st file
    DD = da.iloc[d,0] # get string in dth row of 1st column of 2nd file
    while d<c:
        if D == DD: # match two strings 
            print(da.iloc[0,:]) # if matched then print entire row from 2nd file
            d += 1
    b += 1

0 个答案:

没有答案