使用 Python 将excel 生成json

Python 的 pandas 库是一个强大的数据处理工具,可以轻松地将 Excel 文件转换为 JSON 格式。

步骤:
  1. 安装 Pandas 和 OpenPyXL

    使用 pip 安装 pandasopenpyxl 库:

    复制代码
    pip install pandas openpyxl
  2. 编写 Python 脚本

    创建一个 Python 脚本,例如 excel_to_json.py,内容如下:

    复制代码
    import pandas as pd
    
    def excel_to_json(excel_file, sheet_name, json_file):
        # 读取 Excel 文件
        df = pd.read_excel(excel_file, sheet_name=sheet_name)
        
        # 将 DataFrame 转换为 JSON
        df.to_json(json_file, orient='records', force_ascii=False)
    
    # 示例用法
    excel_to_json('input.xlsx', 'Sheet1', 'output.json')
  3. 运行脚本

    在终端中运行脚本:

    复制代码
    python excel_to_json.py
相关推荐
梨子串桃子_5 小时前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法
文言一心6 小时前
LINUX离线升级 Python 至 3.11.9 操作手册
linux·运维·python
诗词在线6 小时前
中国古代诗词名句按主题分类有哪些?(爱国 / 思乡 / 送别)
人工智能·python·分类·数据挖掘
高锰酸钾_6 小时前
机器学习-L1正则化和L2正则化解决过拟合问题
人工智能·python·机器学习
天天睡大觉7 小时前
Python学习11
网络·python·学习
智航GIS7 小时前
11.11 Pandas性能革命:向量化操作与内存优化实战指南
python·pandas
wtsolutions7 小时前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions7 小时前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
写代码的【黑咖啡】7 小时前
Python中的Selenium:强大的浏览器自动化工具
python·selenium·自动化