PANDAS How to compare two files, json, xml to excel

Question:

I have two files, for example

  1. Excel
ID Price Status
1 1000 Free
2 2000 Option
3 3000 Reserved
  1. JSON
{
            "id": 1,
            "price": "1000",
            "status": "free",
}
{
            "id": 2,
            "localization": "2000",
            "reference": "Option",
}
{
            "id": 3,
            "localization": "3000",
            "reference": "Reserved",
}    

How I should compare these files? Which commands should be useful?

Asked By: SiemowitJarilo

||

Answers:

You can use pandas for this:

from pandas.testing import assert_frame_equal
df1 = pd.read_excel("your excell file path")
df2 = pd.read_json("your json file path") # or you can create using pd.DataFrame.from_dict(your_dict)

assert_frame_equal(df1, df2)  # this will check if two dataframes are equal or not
Answered By: Deepak Tripathi
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.