在 Python 中,可以使用 pandas 库将 JSON 数据转换为 Excel 文件。以下是示例代码:

import pandas as pd
import json

# 读取 JSON 数据
with open('data.json', 'r') as f:
    data = json.load(f)

# 将 JSON 数据转换为 DataFrame
df = pd.DataFrame(data)

# 将 DataFrame 写入 Excel 文件
df.to_excel('data.xlsx', index=False)

在这个示例中,我们首先使用 json.load() 函数读取 JSON 数据。然后,使用 pandas 的 DataFrame 类将数据转换为 DataFrame 对象。最后,我们使用 to_excel() 方法将 DataFrame 写入 Excel 文件。请注意,我们将 index 参数设置为 False,以避免在 Excel 文件中写入索引列。

Python 将 JSON 数据转换为 Excel 文件

原文地址: https://www.cveoy.top/t/topic/oAM8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录