карта не отображается - PullRequest
       64

карта не отображается

0 голосов
/ 12 января 2020

Я начинающий fre sh с Python для Науки о данных, и это мой первый запрос о помощи здесь (затем заранее прошу прощения за некоторые ошибки). Нужна ваша поддержка, чтобы понять, почему эта карта (основанная на простом фрейме данных) не отображается. Прочитайте довольно много дискуссий по этому аргументу, затем я проверил все основные вещи: названия районов и NAAM (в geo json) в str et c - но все же я застрял и не вижу карту (только легенда). Дайте мне знать, если вам нужна дополнительная информация, ниже вы можете найти код: In [9]:

df_clo=dfrc.groupby(['District']).mean()
df_clo.reset_index(inplace=True)
df_clo=df_clo[['District','Rent']]
df_clo['District'] = df_clo['District'].str.upper()
df_clo

Out [9]:

District    Rent
0   BINNENSTAD  1792.281250
1   NOORDOOST   1763.558824
2   OOST    1739.186047
3   ZUID    1562.142857
4   ZUIDWEST    1397.689655

In [10]:

latitude = 52.09083
longitude = 5.12222
print('The geograpical coordinate of Utrecht are {}, {}.'.format(latitude, longitude))# create map of Utrecht using latitude and longitude values
utrecht_geo = r'https://raw.githubusercontent.com/umbesallfi/Coursera_Capstone/master/wijk_.geojson'
# create a numpy array of length 6 and has linear spacing from the minium total immigration to the maximum total immigration
threshold_scale = np.linspace(df_clo['Rent'].min(),
                              df_clo['Rent'].max(),
                              6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration
# let Folium determine the scale.
map_utr = folium.Map(location=[latitude, longitude], zoom_start=2, tiles='Mapbox Bright')
map_utr.choropleth(
    geo_data=utrecht_geo,
    data=df_clo,
    columns=['District', 'Rent'],
    key_on='feature.properties.NAAM',
    threshold_scale=threshold_scale,
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Price in Utrecht by Wijk',
    reset=True
)
map_utr

here map output

1 Ответ

0 голосов
/ 14 января 2020

Названия районов не хранятся печатными буквами в вашем файле wijk_.geojson. Следовательно, должно быть достаточно удалить эту строку:

df_clo['District'] = df_clo['District'].str.upper()

Мой код:

import folium
import pandas as pd
import numpy as np

m = folium.Map(location=[52.09083, 5.12222],
               zoom_start=12,
               control_scale=True)

df_clo = pd.DataFrame({'District':['Binnenstad','Noordoost','Oost','Zuid','Zuidwest'],
                       'Rent':[1792.281250,
                               1763.558824,
                               1739.186047,
                               1562.142857,
                               1397.689655]})

threshold_scale = np.linspace(df_clo['Rent'].min(),
                              df_clo['Rent'].max(),
                              6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration

utrecht_geo = 'wijk_.geojson'

folium.Choropleth(geo_data=utrecht_geo,
                  name='choropleth',
                  data=df_clo,
                  columns=['District', 'Rent'],
                  key_on='feature.properties.NAAM',
                  threshold_scale=threshold_scale,
                  fill_color='YlOrRd',
                  fill_opacity=0.7,
                  line_opacity=0.2,
                  legend_name='Price in Utrecht by Wijk',).add_to(m)

folium.LayerControl().add_to(m)

m

возвращает эту карту:

enter image description here

...