Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #146 from codeforjapan/development
Browse files Browse the repository at this point in the history
development -> master
  • Loading branch information
halsk authored Aug 22, 2020
2 parents ab48014 + ea6deb2 commit 3a6272a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mynumbercard_data/citycode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,34 @@ def add_citycode(self, data: list, header: list) -> list:
cjk = str.maketrans("⻲⻑黑戶⻯⻄⻘⻤", "亀長黒戸竜西青鬼")
df_local = pd.DataFrame(data)
df_local.columns = header
# normalize
df_local["都道府県名"] = df_local["都道府県名"].str.normalize("NFKC")
df_local["市区町村名"] = df_local["市区町村名"].str.normalize("NFKC")
df_local["都道府県名"] = df_local["都道府県名"].apply(lambda s: s.translate(cjk))
df_local["市区町村名"] = df_local["市区町村名"].apply(lambda s: s.translate(cjk))
# remove spaces
df_local["市区町村名"] = df_local["市区町村名"].str.replace(
' ', '').replace(' ', '')
# 都道府県と市区町村を繋げたカラムを作る
df_local.insert(0, '地名', df_local["都道府県名"] + df_local["市区町村名"])
# PDFと市区町村コード表との差異を吸収
df_local["市区町村名"] = df_local["市区町村名"].mask(
df_local["地名"] == "兵庫県篠山市", "丹波篠山市")
df_local["市区町村名"] = df_local["市区町村名"].mask(
df_local["地名"] == "高知県高岡郡梼原町", "高岡郡檮原町")
df_local["市区町村名"] = df_local["市区町村名"].mask(
df_local["地名"] == "福岡県糟屋郡須惠町", "糟屋郡須恵町")
df_local["市区町村名"] = df_local["市区町村名"].mask(
df_local["地名"] == "福岡県筑紫郡那珂川町", "那珂川市")
# マージする
df_local = pd.merge(df_local, self._df_code, on=[
'都道府県名', '市区町村名'], how="left")
df_local["団体コード"] = df_local["団体コード"].astype("Int64")

# errorデータ
if (df_local.isnull().values.sum() > 0):
print("Code is not found")
print(df_local[df_local['団体コード'].isnull()])

df_local.drop("地名", axis=1, inplace=True)
return [df_local.columns.tolist()] + df_local.values.tolist()

0 comments on commit 3a6272a

Please sign in to comment.