我的问题是郊区在 Folium 地图上没有显示正确的颜色。例如,Dandenong 和 Frankston 应该用最深的颜色着色,因为它们在数据框中的计数最高,但它们用较浅的颜色着色。
数据框缺少一些郊区。这些郊区被涂上最深的颜色。
另一个问题是 csv 的所有郊区都是大写的,但 geojson 有多种情况,例如“Frankston”、“St Kilda”或“McKinnon”。如果 choropleth 代码不关心大小写,那将会很有帮助。我可以将数据框中的文本更改为“FRANKSTON”、“Frankston”和“ST KILDA”、“St Kilda”,但事实证明将“MCKINNON”改为“McKinnon”有点棘手。
创建数据框
import csv
import pandas as pd
csv_path='Data_tables_Criminal_Incidents_Visualisation_year_ending_June_2018.csv'
df=pd.read_csv(csv_path)
with open(csv_path, 'r') as csvfile:
# creating a csv reader object
csvreader = csv.reader(csvfile)
# create a list of headings from the first row of the csv file
headings = next(csvreader)
# create a dictionary, where keys are Suburb/Town Name and values are number of occurences
# index 2 of the headings list are …Run Code Online (Sandbox Code Playgroud)