繁体   English   中英

- 从excel文件中读取数据并在python中以json格式返回响应

[英]- 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 );

使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM