I have a JSON file which I want to extract all value in the JSON into Excel.
Each value (from JSON) = 1 column (in Excel).
I don't want to extract it again in Excel. Need final result from Python. But I don't know how to code on this part
CodePudding user response:
you can easily do it with pandas:
import pandas as pd
df_json = pd.read_json(‘DATAFILE.json’)
df_json.to_excel(‘DATAFILE.xlsx’)
or:
import json
import pandas as pd
with open('./SimData/save_to_excel.json') as json_file:
data = json.load(json_file)
df = pd.DataFrame(data)
df.to_excel('./SimData/exported_json_data.xlsx')
CodePudding user response:
You may use Pandas and openpyxl:
First install it pip install pandas openpyxl, and then:
import pandas as pd
df_json = pd.read_json(‘your_input_file.json’)
df_json.to_excel(‘your_output_file.xlsx’)
Take a look: https://www.marsja.se/how-to-convert-json-to-excel-python-pandas/
