Skip to content

Instantly share code, notes, and snippets.



Last active Jun 1, 2016
What would you like to do?
# coding: utf-8
def csv_sort(file, i=0):
import csv
with open(file, "r") as f:
reader = csv.reader(f)
# ヘッダーがあれば除外
# ここで数値をint型に変換してソートする
for row in sorted(reader, key=lambda x:int(x[i]) if x[i].isdigit() else x[i]):
yield row
if __name__ == "__main__":
for row in csv_sort("file.csv"):
print row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment