Scraping Powerpoint (pptx) table

List of open data evangelists of Open Data of the government CIO portal Scraping the pptx table in documents / opendata-dendoushi_ichiran.pptx)

wget https://cio.go.jp/sites/default/files/uploads/documents/opendata-dendoushi_ichiran.pptx -O ichiran.pptx
pip install python-pptx
import pptx
import pandas as pd

prs = pptx.Presentation("ichiran.pptx")

dfs = []

for page in prs.slides:

    data = [[cell.text for cell in row.cells] for row in page.shapes[1].table.rows]

    dfs.append(pd.DataFrame(data[1:], columns=data[0]))

df = pd.concat(dfs).set_index("No.")

df["Affiliation group, etc."] = df["Affiliation group, etc."].str.replace("\n", "", regex=True)

df1 = df.join(
    df["Full name"].str.split("\n", expand=True).rename(columns={0: "Furigana", 1: "name"})
).drop("Full name", axis=1)

df2 = df1.reindex(columns=["name", "Furigana", "Main activity area", "Major achievements so far", "Affiliation group, etc."])

df2.to_csv("ichiran.csv", encoding="utf_8_sig")

Recommended Posts

Scraping Powerpoint (pptx) table
Table scraping with Beautiful Soup
Scraping 1
[Python] Scraping a table using Beautiful Soup