I've rewritten this question a lot, so it's okay now.
Next question <
I want to count the number of cities by province from the csv file
Using Python, we would like to extract prefectures and municipalities from the data of prefectural districts (see image 1).
However, I got an error in image 2 on Python, but I don't know how to solve it.
python regular-expression
Here is a brief example of re.search
.
import re
s=["Tokyo", "Hokkaido", "Nagasaki Prefecture", "Kyoto Prefecture", "Nagoya City"]
for iins:
print(re.search("City | Road | Prefectural | Prefectural", i))
# <re. Match object; span=(2,3), match='City'>
# <re. Match object; span=(2,3), match='road'>
# <re. Match object; span=(2,3), match='Prefect'>
# <re. Match object; span=(1,2), match='City'>
# None
Please enclose the regular expression with "
I want to extract prefectures and municipalities from the data of prefectural districts.
KEN_ALL.CSV
may have been downloaded from Japan Postcode Data Download The kana data's prompt and sulky sounds are written in small letters from State and city names are listed in columns 7 and 8 respectively, so you will have to extract them.
import csv
filename = 'KEN_ALL.CSV'
prefs, cities = [ ], [ ]
with open(filename, encoding='Shift JIS', newline=')asf:
csvreader=csv.reader(f)
for row in csvreader:
prefs.append(row[6])#7th column: State/Province name
cities.append(row[7])#8th column: City name
# Remove Duplicate
prefix=[*{*prefs}]
cities=[*{*cities}]
print(prefs)#47 cases
# print(cities)#1894 cases
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
578 Understanding How to Configure Google API Key
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.