差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン 次のリビジョン両方とも次のリビジョン | ||
python:csvファイル読み込み [2019/06/12 09:23] – 作成 baba | python:csvファイル読込書込 [2020/04/21 10:04] – ↷ python:csvファイル読み込み から python:csvファイル読込書込 へページを名称変更しました。 baba | ||
---|---|---|---|
行 1: | 行 1: | ||
====== CSVファイルを読み込む ====== | ====== CSVファイルを読み込む ====== | ||
+ | <code .py read.py> | ||
+ | import csv | ||
+ | f = open(' | ||
+ | reader = csv.reader(f, | ||
+ | for r in reader: | ||
+ | print r | ||
+ | </ | ||
+ | |||
+ | x[1]にはソートキーを入れる | ||
+ | <code .py readSorted.py> | ||
+ | import csv | ||
+ | |||
+ | f = open(' | ||
+ | reader = csv.reader(f, | ||
+ | sorted_data = sorted(reader, | ||
+ | for d in sorted_data: | ||
+ | print d | ||
+ | f.close() | ||
+ | </ |