1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

総務省 電気通信番号指定状況の携帯電話・PHSの電話番号の一覧からCSVを作成する

Posted at

総務省 電気通信番号指定状況の携帯電話・PHSの電話番号
Excelから事業者一覧を取り出しCSVに変換

import pandas as pd

df_070 = (
    pd.read_excel(
        "https://www.soumu.go.jp/main_content/000697563.xlsx", skiprows=5, dtype=str
    )
    .set_index("番号")
    .stack()
)
df_080 = (
    pd.read_excel(
        "https://www.soumu.go.jp/main_content/000697565.xlsx", skiprows=5, dtype=str
    )
    .set_index("番号")
    .stack()
)
df_090 = (
    pd.read_excel(
        "https://www.soumu.go.jp/main_content/000697567.xlsx", skiprows=4, dtype=str
    )
    .set_index("番号")
    .stack()
)

# 結合
df = pd.concat([df_070, df_080, df_090]).reset_index()

# 列名変更
df.rename(columns={"番号": "CD", "level_1": "E", 0: "事業者"}, inplace=True)

# 半角
df["E"] = df["E"].str.normalize("NFKC")

# 結合
se = df["CD"] + df["E"] + "XXXXX"

# 電話番号表記
df["番号"] = se.str[:3] + "-" + se.str[3:7] + "-" + se.str[7:]

df

df.to_csv("number.csv", encoding="utf_8_sig")
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?