How to solve the below file content comparision problem using python/pandas?

Viewed 34

I have 2 files, fruits1.txt and fruits2.txt. The structure of the file is such that under exotic|| there are apple|| which are unique to it. exotic and pink together form a key. Same way apple and 7.0 under it forms a key. i.e. for example in file1 I need to compare the below data exotic|pink|anothertext apple|2.0|red orange|1.0|blue

with the corresponding matching data. exotic|pink apple|7.0|red mango|4.0|yellow berry|3.0|blue|red

fruit1.txt has the below content:

exotic|pink|anothertext apple|2.0|red orange|1.0|blue exotic|blue|anothertext apple|7.0|red mango|4.0|yellow berry|3.0|blue

fruit2.txt has the below content:

exotic|blue|anothertext apple|2.0|green orange|1.0|blue exotic|pink apple|7.0|red mango|4.0|yellow berry|3.0|blue|red

I need to compare both the files based on keys and get the below differences. 1)mismatch of data example: file1: apple|2.0|green file2: apple|2.0|red ->green & red has mismatch

2)data missing in file 1 but present in file 2 example: file1: apple|2.0| file2: apple|2.0|red ->green & red has mismatch

3)data missing in file 2 but present in file 1

4)additional data example: file1: apple|2.0|green|tree file2: apple|2.0|green ->tree is additional data in file1.

Can anybody please help with the approach to solve this problem & please let me know if anything is needed. Thanks in advance.

0 Answers
Related