Home > AI > Language > Python >

Convert Excel to JSON

import pandas as pd
import json


filename = 'tpg'


df = pd.read_excel(filename + '.xlsx')

# change date
date_format="%Y-%m-%d"
for column in df.select_dtypes(include=['datetime']):
    df[column] = df[column].dt.strftime(date_format)


json_data = df.to_json(orient='records', force_ascii=False, indent=4)
with open(filename + '.json', 'w', encoding='utf-8') as json_file:
    json_file.write(json_data)

Leave a Reply