Home > front end >  PANDAS How to compare two files, json, xml to excel
PANDAS How to compare two files, json, xml to excel

Time:10-05

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?

CodePudding user response:

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
  • Related