都道府県別の郵便番号数順位を調べてみた


郵便番号数の都道府県別順位を調べたところで何の役にも立たないのですが,自作した CsvReader のテストに使えるかなと思いやってみました。使用したデータは日本郵便で公開されている郵便番号データ (平成 22 年 1 月 29 日更新版) を利用しました。

データ中には下 4 桁が 0000 で終わるものがありますが,これは除いてカウントしています。

北海道	7,939
愛知県	6,891
京都府	6,389
新潟県	5,341
兵庫県	5,139
大阪府	3,699
東京都	3,604
福島県	3,573
千葉県	3,535
岐阜県	3,318
福岡県	3,232
富山県	2,961
埼玉県	2,870
静岡県	2,846
茨城県	2,816
宮城県	2,764
三重県	2,439
石川県	2,436
神奈川県	2,230
岡山県	2,168
秋田県	2,144
福井県	2,115
広島県	2,094
青森県	2,010
山形県	1,923
奈良県	1,893
長崎県	1,882
熊本県	1,851
大分県	1,820
滋賀県	1,819
栃木県	1,817
岩手県	1,767
愛媛県	1,720
高知県	1,668
長野県	1,649
山口県	1,613
和歌山県	1,584
群馬県	1,488
鹿児島県	1,418
鳥取県	1,385
島根県	1,166
徳島県	954
山梨県	929
宮崎県	863
佐賀県	859
沖縄県	785
香川県	697

北海道は広いだけあって堂々の 1 位ですね。かと思いきや愛知,京都が上位にあったりして不思議ですね。東京は結構少ないのですが,内部で頑張っているのでしょうか。

使用したコードを次に示します。 LINQ って便利ですね。変な手の抜き方をしているのは気にしないでください。

ところで私は郵便番号を postal code と訳すのですが,日本郵便の URL は zipcode となっています。日本的に ZIP code ってどうなんでしょう。

CsvReaderSettings settings = new CsvReaderSettings()
{
	Encoding = Encoding.GetEncoding(932),
	Separator = ",",
};

using (CsvReader reader = new CsvReader("KEN_ALL.CSV", settings))
{
	var prefectures = from record in reader.ReadToEnd().Distinct(new PostalCodeComaparer())
		where record.PostalCode.Lower != "0000"
		group record by record.Prefecture into prefecture
		orderby prefecture.Count() descending
		select prefecture;
	foreach (var prefecture in prefectures)
	{
		Console.WriteLine("{0}\t{1:#,0}", prefecture.Key, prefecture.Count());
	}
}
public struct PostalCord : IParser, IEquatable
{
	public string Upper;
	public string Lower;

	public PostalCord(string upper, string lower)
	{
		Upper = upper;
		Lower = lower;
	}

	public object Parse(string value)
	{
		Upper = value.Substring(0, 3);
		Lower = value.Substring(3, 4);
		return this;
	}

	public override int GetHashCode()
	{
		return int.Parse(Upper + Lower);
	}

	public override bool Equals(object obj)
	{
		if (obj == null || !(obj is PostalCord))
		{
			return false;
		}
		return Equals((PostalCode)obj);
	}

	public bool Equals(PostalCord other)
	{
		return this.Upper == other.Upper && this.Lower == other.Lower;
	}
}
public struct PostalCodeRecord
{
	[RecordField(2, ParserType = typeof(PostalCord))]
	public PostalCord PostalCode;
	[RecordField(6)]
	public string Prefecture;
}
public class PostalCodeComaparer : IEqualityComparer
{
	public bool Equals(PostalCodeRecord x, PostalCodeRecord y)
	{
		return x.PostalCode.Equals(y.PostalCode);
	}

	public int GetHashCode(PostalCodeRecord obj)
	{
		return obj.PostalCode.GetHashCode();
	}
}