How to convert JSON to XLS in Python

前端 未结 4 1207
梦毁少年i
梦毁少年i 2020-12-29 08:03

Does anyone know how can I convert JSON to XLS in Python?

I know that it is possible to create xls files using the package xlwt

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 08:28

    If your json file is stored in some directory then,

    import pandas as pd
    pd.read_json("/path/to/json/file").to_excel("output.xlsx")
    

    If you have your json within the code then, you can simply use DataFrame

    json_file = {'name':["aparna", "pankaj", "sudhir", "Geeku"],'degree': ["MBA", "BCA", "M.Tech", "MBA"],'score':[90, 40, 80, 98]}
    df = pd.DataFrame(json_file).to_excel("excel.xlsx")
    

提交回复
热议问题