Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python choropleth地图未显示_Python_Python 3.x_Geojson_Folium_Choropleth - Fatal编程技术网

Python choropleth地图未显示

Python choropleth地图未显示,python,python-3.x,geojson,folium,choropleth,Python,Python 3.x,Geojson,Folium,Choropleth,我是数据科学Python的新手,这是我在这里的第一个帮助请求(然后为一些错误提前道歉)。 需要您的支持,以了解此(基于简单数据帧的)choropleth地图未显示的原因。读了好几篇关于这个论点的讨论,然后我验证了所有主要内容:str中的地区名称和NAAM(在geojson中)等,但我仍然被卡住了,看不到地图(只有图例)。让我知道如果需要更多信息,您可以在下面找到代码: 在[9]中: 出[9]: District Rent 0 BINNENSTAD 1792.281250 1 NO

我是数据科学Python的新手,这是我在这里的第一个帮助请求(然后为一些错误提前道歉)。 需要您的支持,以了解此(基于简单数据帧的)choropleth地图未显示的原因。读了好几篇关于这个论点的讨论,然后我验证了所有主要内容:str中的地区名称和NAAM(在geojson中)等,但我仍然被卡住了,看不到地图(只有图例)。让我知道如果需要更多信息,您可以在下面找到代码: 在[9]中:

出[9]:

District    Rent
0   BINNENSTAD  1792.281250
1   NOORDOOST   1763.558824
2   OOST    1739.186047
3   ZUID    1562.142857
4   ZUIDWEST    1397.689655
在[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

地区名称不会以正楷形式存储在您的
wijk_jk.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
返回此映射:


@umbesallfi如果我的回答解决了你的问题,请接受。
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