python将json数据转excel或csv
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
需要用到的模块
python pandas模块
pip install pandas
python pandas
pandas是python语言的一个扩展程序库,用于数据分析。
示例
将json数据转换为excel数据
import pandas as pd
df = pd.read_json('1.json')
df.to_excel('aaa.xlsx')
print("*****************************")
输出如下
将json数据转换为csv数据
import pandas as pd
df = pd.read_json('1.json')
df.to_csv('demo.csv')
print("*****************************")
输出如下
json数组转换
import pandas as pd
df = pd.read_json("demo.json")
print(df)
print("================================")
data = pd.DataFrame(df["namelist"]["names"])
data.to_excel("demo.xlsx")
print("********************************")
输出如下
其他
import pandas as pd
# 你的 JSON 数据
data = {
"TraceApps": [
{
"ResourceGroupId": "rg-xssd2ee",
"ClusterId": "xxxxxssxcssd2",
"CreateTime": 1620000000,
"Pid": "xxxx@xxx",
"Labels": [],
"Source": "ACSK8S",
"Namespace": "tr",
"AppName": "xx-xx-xx-xx",
"Type": "TRACE",
"AppId": 123456,
"Language": "java",
"UserId": "xxxxx",
"UpdateTime": 1620000000,
"Show": True,
"RegionId": "cn-shanghai"
}
]
}
# 提取数据
trace_apps = data['TraceApps']
# 只保留指定的键
selected_keys = ["ResourceGroupId", "ClusterId", "AppName", "Language"]
filtered_data = [{key: app.get(key, None) for key in selected_keys} for app in trace_apps]
# 将数据转换为 DataFrame
df = pd.DataFrame(filtered_data)
# 将 DataFrame 保存为 Excel 文件
df.to_excel('trace_apps_filtered.xlsx', index=False)
print("数据已成功保存为 trace_apps_filtered.xlsx")
GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
f06604fc
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> 3 天前
d23291ba
* add a ci step for Json_Diagnostic_Positions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* Update ci.cmake to address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typo in the comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typos in ci.cmake
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* invoke the new ci step from ubuntu.yml
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* issue4561 - use diagnostic positions for exceptions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci check failures for unit-diagnostic-postions.cpp
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* improvements based on review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix const correctness string
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* further refinements based on reviews
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add one more test case for full coverage
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* ci check fix - add const
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add unit tests for json_diagnostic_postions only
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_diagnostics
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_build_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
---------
Signed-off-by: Harinath Nampally <harinath922@gmail.com> 3 天前
更多推荐
已为社区贡献3条内容
所有评论(0)