a.csv
number address
------ -------
1
2
3
4
5
b.csv
number address1 address2
------ -------- --------
2 abc def
3 abc1 def1
4 abc2 def2
Numbers 2 , 3 and 4 found in both a and b.csv. So I want the final output in the a.csv file itself like below:
number address
------ -------
1
2 abc def
3 abc1 def1
4 abc2 def2
5
Code I tried:
nos = []
with open("a.csv", "r") as# Skip the first line
f.readline()
for line in f:
nos.append(int(line.strip("\n")))
with open("b.csv", "r") as f:
f.readline()
for line in f:
if int(line.split(",")[1]) in nos:
How to write into a.csv file itself back?