compare two csv files and print the unique string in 3rd csv file

0 votes
csv1:hello world

        wonder land

csv2:world

        wonder

csv3:output= hello

                    land
Jun 1, 2020 in Python by anonymous
• 120 points
3,264 views

1 answer to this question.

0 votes

Hi, @Smilish,

I hope this below code will help you:

file_list = ['Sample1.csv', 'Sample2.csv']
f1 = open(file_list[0], 'r').readlines() 
f2 = open(file_list[1], 'r').readlines() 
fName = open('output.csv', 'a') 
for _ in range(2): 
for row in f1:
 if row not in f2: 
fName.write(row)
 f1, f2 = f2, f1
answered Jun 1, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
2 answers
0 votes
1 answer

How to find the value of a row in a csv file in python and print column and row of that value ?

Hello @Khanhh , Use panda to find the value of ...READ MORE

answered Oct 15, 2020 in Python by Niroj
• 82,560 points
949 views
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,780 points
1,237 views
0 votes
1 answer

how do i print only the last two letters in a string using regular expression in python?

$ to match the end of the ...READ MORE

answered Mar 15, 2019 in Python by Waseem
• 4,540 points
221 views
+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
543 views
0 votes
0 answers

Storing a list of arrays into a CSV file and retrieving it back in a different program

This is the code that I am ...READ MORE

Jun 6, 2018 in Python by aryya
• 7,420 points
1,042 views
0 votes
1 answer

Replace First and Last Word of String in the Most Pythonic Way

import re a = " this is a ...READ MORE

answered Aug 22, 2018 in Python by aryya
• 7,420 points
772 views
0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 58,100 points
1,811 views
0 votes
1 answer

how can i extact all the links from a website using python and save it in a csv file ?

Hi, @Shubham, Web scraping is the technique to ...READ MORE

answered Jun 16, 2020 in Python by Gitika
• 65,870 points
1,266 views
0 votes
1 answer

What is the difference between .py and .pyc files in Python?

Hi, @Roshni, You can follow a few steps ...READ MORE

answered Jun 23, 2020 in Python by Gitika
• 65,870 points
1,530 views