Last active
October 4, 2019 13:38
-
-
Save hamaguchi-amago/85204b53ed786a663abcf0c583ad37d1 to your computer and use it in GitHub Desktop.
CSVファイルの読み込み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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("国語")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
名前 | 国語 | 算数 | 英語 | |
---|---|---|---|---|
太郎 | 90 | 80 | 70 | |
次郎 | 75 | 85 | 90 | |
三郎 | 95 | 100 | 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ブログの記事で作成しました。
興味のある方はご覧ください。
【Python】CSVファイルの基本操作(読み込み)
https://neko-py.com/python-csv-read