Skip to content

Instantly share code, notes, and snippets.

@hamaguchi-amago
Last active October 4, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamaguchi-amago/85204b53ed786a663abcf0c583ad37d1 to your computer and use it in GitHub Desktop.
Save hamaguchi-amago/85204b53ed786a663abcf0c583ad37d1 to your computer and use it in GitHub Desktop.
CSVファイルの読み込み
# -*- coding: utf-8 -*-
import csv
with open('read_data.csv', 'r') as f:
reader = csv.reader(f)
header = next(reader)
print("ヘッダー行:")
print(header)
data = next(reader)
print("データ行(next):")
print(data)
for row in reader:
print("データ行:")
print(row)
print("名前:" + row[0])
print("国語:" + row[1])
print("算数:" + row[2])
print("英語:" + row[3])
# -*- coding: utf-8 -*-
import csv
with open('read_data.csv', 'r') as f:
for row in csv.DictReader(f):
print(row)
print(row["名前"])
print(row.get("国語"))
名前 国語 算数 英語
太郎 90 80 70
次郎 75 85 90
三郎 95 100 80
@hamaguchi-amago
Copy link
Author

ブログの記事で作成しました。
興味のある方はご覧ください。

【Python】CSVファイルの基本操作(読み込み)
https://neko-py.com/python-csv-read

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment