To store excel data in a JSON file using python

To store excel data in a JSON file using python .

Firstly we need to install the necessary libraries using pip install pandas openpyxl

import pandas as pd

then load  the Excel file by using

1.excel_file = ‘your_file.xlsx’

now we have to read the excel file into a Dataframe that is

2.df = pd.read_excel(excel_file)

convert the dataframe to a JSON string by using

3.json_data = df.to_json(orient=’records’,indent=4)

now we have to save the JSON string to a file by using

with open(‘output_file.json’,’w) as json_file: json_file.write(json_data)

now we have to print

print(“Data successfully written to output_file.json”)

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top