Skip to content

Instantly share code, notes, and snippets.

@tokibito
Created October 11, 2015 04:48
Show Gist options
  • Select an option

  • Save tokibito/89a05e509311f7903610 to your computer and use it in GitHub Desktop.

Select an option

Save tokibito/89a05e509311f7903610 to your computer and use it in GitHub Desktop.
def split(text):
"""カンマで分割
"""
return text.split(',')
def strip_quote(text):
"""クォート除去
"""
return text[1:-1]
def main():
table = []
# CSVファイルの読み込み
with open("KEN_ALL_ROME.CSV", encoding="cp932") as fp:
for line in fp:
data = split(line.strip())
values = []
for cell_text in data:
# 1セル内のデータ
value = strip_quote(cell_text)
values.append(value)
table.append(values)
# 1県あたり何件のデータがあるか
result = {}
for row in table:
ken = row[1]
if ken in result:
result[ken] += 1
else:
result[ken] = 1
# 結果を表示
for ken in sorted(result.keys()):
print("{}: {}".format(ken, result[ken]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment