How to compare 2 dataframes from XLSX with pandas

Viewed 17

I'm working with 2 Excel files that contains some common values but not in the same order.

Df1 :

Siren Categorie
143890789 GE
284928492 PME
398938159 ETI
018583198 PME
385981983 PME

Df2 :

Siret Type
284928492 000 TPE
143890789 245 GE
018583198 535 PME
398938159 513 ETI
385981983 555 PME

Result :

Siren Categorie Siret Type Verify
284928492 PME 284928492 000 TPE False
284928492 GE 143890789 245 GE True
284928492 PME 018583198 535 PME True
284928492 ETI 398938159 513 ETI True
284928492 PME 385981983 555 PME True

My main goal is to compare Siren and Categorie (together, like a group) with Siret and Type to see if the value from Siren & Categorie are the same than Siret & Type. Example :

143890789:GE Df1

143890789:GE Df2

Df1 = Df2 so I will write in a new column "Verify" True or false or anything else.

First I need to remove the last 3 digits of Siret to get the same format that Siren, I tried to use a range but it just

Second I need to order them the same, but in the real table I have like few hundreds values so I can't do it manually, how can I do ?

Third I need to link Siren & Categorie and Siret & Type then check if value are the same from Siren and Siret

Fourth do sth when type & categorie are not the same.

How can I do that ? Thanks you !

0 Answers
Related