-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop_util.py
More file actions
39 lines (36 loc) · 1.25 KB
/
pop_util.py
File metadata and controls
39 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from jaconv import z2h
import datetime
def getDate(matrix):
westernDate = ""
colCounter = 0
while westernDate == "":
if matrix[0][colCounter].find("平成") != -1:
hankaku = z2h(matrix[0][colCounter], digit=True)
heisei = hankaku.find("平成")
nen = hankaku.find("年", heisei)
gatsu = hankaku.find("月", heisei)
nichi = hankaku.find("日", heisei)
y = int(hankaku[(heisei+2):nen]) + 1988
m = int(hankaku[(nen+1):gatsu])
d = int(hankaku[(gatsu+1):nichi])
westernDate = datetime.datetime(y, m, d)
colCounter = colCounter + 1
return str(westernDate)
def extractData(matrix, date):
popData = []
cityTypes = ["市","町","村"]
# find starting point
rowCounter = 1
while matrix[rowCounter][0].find("福") == -1:
rowCounter = rowCounter + 1
while rowCounter <= len(matrix) - 1 and len(matrix[rowCounter][0]) > 0:
# print(matrix[rowCounter][0])
if matrix[rowCounter][0][-1] in cityTypes:
cityName = matrix[rowCounter][0].replace(" ","")
if matrix[rowCounter][1] == "-":
totalPopulation = 0
else:
totalPopulation = int(matrix[rowCounter][1])
popData.append([date, cityName, totalPopulation])
rowCounter = rowCounter + 1
return popData