읽기
import pandas as pd
data = pd.read_csv(path)
쓰기 (한 줄씩)
import csv
name = ['id', 'eng', 'kor']
data = [
['1', 'apple', '사과'],
['2', 'school', '학교'],
['3', 'hospital', '병원'],
['4', 'hat', '모자'],
]
f = open("vocabularay.csv", "w")
writer = csv.writer(f)
writer.writerow(name)
for row in data:
writer.writerow(row)
f.close()
쓰기 (한 번에)
import csv
data = [
['id', 'eng', 'kor'],
['1', 'apple', '사과'],
['2', 'school', '학교'],
['3', 'hospital', '병원'],
['4', 'hat', '모자']
]
f = open("vocabulary.csv", "w")
writer = csv.writer(f)
writer.writerows(data)
f.close()
'코딩 공부 > Python' 카테고리의 다른 글
[Python] json, jsonl 파일 읽고 쓰기 (0) | 2025.04.21 |
---|---|
[Python] 간단한 random 함수 기능 정리 (+ numpy.random) (1) | 2025.04.18 |