[英]- read data from excel file and return response in json format in python
import pandas
def extract(local_path,file_name):
#Read excel file and store in to DataFrame
data = pd.read_excel( file_name );
Read data from the excel file with pandas.read_excel()
, then convert it to dictionary object with .to_dict()
method and convert it to json format with json.dumps()
method froom json module使用
pandas.read_excel()
从 excel 文件中读取数据,然后使用.to_dict()
方法将其转换为字典对象,并使用.to_dict()
方法将其转换为 json 格式json.dumps()
json 模块
import pandas as pd
import json
def extract(file_name):
#Read excel file and store in to DataFrame
data = pd.read_excel( file_name )
data_dict = data.to_dict()
data_json = json.dumps(data_dict)
return data_json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.