Efficient method for matching data in multiple csv files
<p>Here is a snippet of my code:</p>

<pre><code>for i,r1 in enumerate(Solution.values):
    h1=ProjectedRevenue.index[i]
    District_ID,Instrument_ID,Buy_or_not,Revenue=r1
    listSol=[]
    listSol.append(h1)
    listSol.append(list(r1)[0])
    listSol.append(list(r1)[1])
    for j,r2 in enumerate(ProjectedRevenue.values):
        h2=ProjectedRevenue.index[j]
        if h2 == listSol[0]:
            District_ID,Instrument_ID,Annual_Projected_Revenue= r2
            listPR=list(r2)
            if listSol[1] == listPR[1] &amp; listSol[2] == listPR[2]:
                if(listPR[2]&gt;0):
                    #do stuff
                    continue
                else:
                    #do stuff
                    continue
</code></pre>

<p>I need some help regarding this code. I'm new to python, and I have to search and compare data entries from multiple .csv files. I have seen itertuples but it is not able to recognise the function. So I just made this to search and perform operations via pandas but this has a complexity of $O(n^2)$ and is very slow. Any help regarding this?</p>

<p><strong>EDIT</strong>: So I am using pandas and numpy in the code to manipulate data. And to make it more clear, I need to do a search such that elements of the same index coloumns in two different files are same. Consider the example below:</p>

<p>Solution.csv:</p>

<pre><code>Hospital_ID,District_ID,Instrument_ID
1,4,6
2,5,4
7,8,5
</code></pre>

<p>ProjectedRevenue.csv:</p>

<pre><code>Hospital_ID,District_ID,Instrument_ID
9,3,5
7,8,5
1,2,6
</code></pre>

<p>So here the common entry is 7,8,5 in the two files.I want to know the fastest way to search and match them.</p>

<p><strong>UPDATE</strong>: The previous question was about a syntax error which is resolved.</p>