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 in Python by anonymous
• 120 points
104 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 by Gitika
• 31,430 points

Related Questions In Python

0 votes
1 answer
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,770 points
710 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,530 points
119 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
298 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,370 points
320 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,370 points
205 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
• 57,530 points
661 views
+1 vote
1 answer

Python: Print variable and string in same line

For a better understanding you can refer ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 57,530 points
420 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 in Python by Gitika
• 31,430 points
41 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 in Python by Gitika
• 31,430 points
31 views