troubleshooting Question

Python : how to remove duplicated row from output.

Avatar of Newton
Newton asked on
Python
5 Comments1 Solution110 ViewsLast Modified:
Hi,
I got 2 files i.e File1 and File2, as shown below

File1
A | APPLE
B | ORANGE

File2
A | 10
B | 15
D | 20
A | 10

I need following output
Output 1
A | APPLE | 10
B | ORANGE | 15

But I am getting this below output.
A | APPLE | 10
B | ORANGE | 15
A | APPLE | 10

How can I remove the duplicate rows from the output and direct only the duplicate output to a new file.

My code is as follow

Import pandas as pd
df1 = pd.read_csv('file1.txt', sep='|')
df2 = pd.read_csv('file2.txt', sep='|')
Merge12 = pd.merge(df1, df2, how='left', on='A')
Merge12.to_csv('output.txt')
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros