ken_all csv
- http://www.post.japanpost.jp/zipcode/download.html
- http://www.post.japanpost.jp/zipcode/dl/roman-zip.html
Pythonバージョン 3.4
ken_all csv
Pythonバージョン 3.4
| 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() |