使用python将json文件映射到excel [英] Mapping a json file to excel with python
问题描述
我想把一个json格式的文件映射成一个xls文件.即在输入文件
<代码>{结果": [{"promo_video": "https:\/\/www.youtube.com\/embed\/Tztev0Q-CN8?ps=play&vq=large&rel=0&autohide=1&showinfo=0&autoplay=1",iap":真的,下载":10,000,000"}]}
显示在一个 excel 文件中:列标题:宣传视频|爱普 |下载以及每列的相应值
了解推荐的方法和语法示例会很有帮助.
谢谢.
您可以将 pandas
模块与 xlwt
或 等 Excel 编写器引擎模块一起使用xlsxwriter
用于将 json
映射到 XLS
文件.例如
如果你的 json
是
将此json
转换成XLS
文件
将pandas导入为pdjson_text = """[{"key_1":"foo1","key_2":"bar1","key_3":"foobar1"},{"key_1":"foo2","key_2":"bar2","key_3":"foobar2"}]"""df = pd.read_json(json_text)df.to_excel('output.xls', index=False)
I would like to take a json format file and map it into an xls file. i.e. in the input file
{
"results": [
{
"promo_video": "https:\/\/www.youtube.com\/embed\/Tztev0Q-CN8?ps=play&vq=large&rel=0&autohide=1&showinfo=0&autoplay=1",
"iap": true,
"downloads": "10,000,000"
}
]
}
to be presented in an excel file: column headers: promo video| iap | downloads and the respective values of each column
Would be helpful to know a recommended way and syntax example.
Thank you.
You can use pandas
module along with an excel writer engine module such as xlwt
or xlsxwriter
for mapping json
to XLS
file. For example
If your json
is
[
{"key_1":"foo1","key_2":"bar1","key_3":"foobar1"},
{"key_1":"foo2","key_2":"bar2","key_3":"foobar2"}
]
To convert this json
into XLS
file
import pandas as pd
json_text = """
[
{"key_1":"foo1","key_2":"bar1","key_3":"foobar1"},
{"key_1":"foo2","key_2":"bar2","key_3":"foobar2"}
]
"""
df = pd.read_json(json_text)
df.to_excel('output.xls', index=False)
这篇关于使用python将json文件映射到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!