티스토리 뷰

개발 일반

[python] csv를 json 포맷으로 바꾸기

Demis Tae Kyu Eom 2020. 1. 6. 15:53

간단한 내용이지만 막상 하려고 하니 조금 시간이 걸려서 정리해둡니다.

import csv
import json

csvfile = open('file.csv', 'r')
jsonfile = open('file.json', 'w')

fieldnames = ("FirstName","LastName","IDNumber","Message")
reader = csv.DictReader( csvfile, fieldnames)
for row in reader:
    json.dump(row, jsonfile)
    jsonfile.write('\n')

https://stackoverflow.com/questions/19697846/how-to-convert-csv-file-to-multiline-json

 

 

How to convert CSV file to multiline JSON?

Here's my code, really simple stuff... import csv import json csvfile = open('file.csv', 'r') jsonfile = open('file.json', 'w') fieldnames = ("FirstName","LastName","IDNumber","Message") reader ...

stackoverflow.com

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함