python - 将 Flatten CSV 转换为嵌套 JSON
解决方案
You can read about csv module here: https://docs.python.org/3/library/csv.html
There is a class there called DictReader which takes a CSV file and puts it in a dictionary, and from there the way to json is easy.
The following example is presented there:
import csv
with open('names.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row['first_name'], row['last_name'])
Output:
Eric Idle John Cleese
推荐阅读
- c++ - 如何以正确的格式获取 UTC 偏移量(时区)?
- python-3.x - msvcrt.kbhit() 总是返回 false 。无法检测到 Escape 键
- c# - Linq 查询返回列表中的项目,其中包含另一个列表
- amazon-web-services - 是否可以根据每个实例 ID 为 AWS AutoScalingGroup 中的每个实例配置 IAM 权限?
- javascript - 续集年份和月份
- javascript - Firebase 模块在 Svelte 中导致“registerComponent”错误
- sql - DB2 SQL 查询以获取过去更改经理的员工列表
- prisma - 找不到命令:nexus
- git - 错误地创建了新分支
- c# - Visual Studio 2019 .NET Core 3.1 WinForm 视图超时 (Studio 16.7.3)