Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user authored and ryo-ma committed Feb 18, 2024
1 parent 77a39ba commit 5bd906f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
14 changes: 0 additions & 14 deletions action.py

This file was deleted.

19 changes: 2 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import pandas as pd
import tabula
from action import integrate
import os
import shutil
from prefecture import prefectures

if not os.path.exists("./files"):
os.mkdir("./files")

if not os.path.exists("./output_files"):
os.mkdir("./output_files")

for i in range(1, 47):
opendata_file = os.listdir(f"./data_files/shinryoujo_{i}")
dfs = tabula.read_pdf(f"./data_files/shinryoujo_{i}/{opendata_file[0]}", lattice=True, pages='all', pandas_options={'header': None})
j = 0
for df in dfs:
j += 1
df = df.replace('\n', '', regex=True).replace('\r', '', regex=True).replace('\r\n', '', regex=True).replace('\n\r', '', regex=True)
print(df)
if j == 1:
df_header = df.iloc[:2]
print(df_header)
df.to_csv(f"./files/{j}.csv", index=None)
integrate("./files", f"./output_files/output_{prefectures[i-1]}.csv")
shutil.rmtree("./files")
os.mkdir("./files")
merged_df = pd.concat(dfs).replace('\n', '', regex=True).replace('\r', '', regex=True).replace('\r\n', '', regex=True).replace('\n\r', '', regex=True)
merged_df.to_csv(f"./output_files/{prefectures[i-1]}.csv", index=None)

shutil.rmtree("./files")

0 comments on commit 5bd906f

Please sign in to comment.