Python file matching and appending
<p>This is one file <code>result.csv</code>:</p>

<pre><code>M11251TH1230 
M11543TH4292 
M11435TDS144
</code></pre>

<p>This is another file <code>sample.csv</code>:</p>

<pre><code>M11435TDS144,STB#1,Router#1 
M11543TH4292,STB#2,Router#1 
M11509TD9937,STB#3,Router#1
M11543TH4258,STB#4,Router#1
</code></pre>

<p>Can I write a Python program to compare both the files and if line in <code>result.csv</code> matches with the first word in the line in <code>sample.csv</code>, then append 1 else append 0 at every line in <code>sample.csv</code>?</p>

<pre><code>import pandas as pd

d1 = pd.read_csv("1.csv",names=["Type"])
d2 = pd.read_csv("2.csv",names=["Type","Col2","Col3"])
d2["Index"] = 0

for x in d1["Type"] :
    d2["Index"][d2["Type"] == x] = 1

d2.to_csv("3.csv",header=False)
</code></pre>

<p>Considering "1.csv" and "2.csv" are your csv input files and "3.csv" is the result you needed</p>

python append