可以合并两个列表来填充 Jupyter Gmaps info_box 吗?
Can two lists be combined to populate a Jupyter Gmaps info_box?
我正在尝试让 Gmaps 中的弹出框显示来自两个不同列表的信息。当我使用 'and' 组合我的 info_box_content 时,弹出窗口中只显示失业率。当我注释掉第二个列表(如图所示)时,会显示贫困率信息。这可能吗?
poverty_rate = census_data["Poverty Rate"].tolist()
unemployment_rate = census_data["Unemployment Rate"].tolist()
marker_locations = census_data[['Latitude', 'Longitude']]
fig = gmaps.figure()
markers = gmaps.marker_layer(marker_locations,
info_box_content=[f"Poverty Rate: {rate}" for rate in poverty_rate]) #and [f"Unemployment Rate:
{un_rate}" for un_rate in unemployment_rate
fig.add_layer(markers)
fig
info_box 参数采用一个列表,每个标记都有一个字符串。您可以根据需要创建该字符串。例如,您可以这样写:
info_box_content = [
f"Poverty Rate: {poverty_rate_value}, Unemployment rate: {unemployment_rate_value}"
for poverty_rate_value, unemployment_rate_value
in zip(poverty_rate, unemployment_rate
]
markers = gmaps.marker_layer(marker_locations, info_box_content)
请注意,您可以在模板中使用任意 HTML,这样您就可以很好地格式化您的字符串。有关示例,请参阅 the tutorial on markers。
我正在尝试让 Gmaps 中的弹出框显示来自两个不同列表的信息。当我使用 'and' 组合我的 info_box_content 时,弹出窗口中只显示失业率。当我注释掉第二个列表(如图所示)时,会显示贫困率信息。这可能吗?
poverty_rate = census_data["Poverty Rate"].tolist()
unemployment_rate = census_data["Unemployment Rate"].tolist()
marker_locations = census_data[['Latitude', 'Longitude']]
fig = gmaps.figure()
markers = gmaps.marker_layer(marker_locations,
info_box_content=[f"Poverty Rate: {rate}" for rate in poverty_rate]) #and [f"Unemployment Rate:
{un_rate}" for un_rate in unemployment_rate
fig.add_layer(markers)
fig
info_box 参数采用一个列表,每个标记都有一个字符串。您可以根据需要创建该字符串。例如,您可以这样写:
info_box_content = [
f"Poverty Rate: {poverty_rate_value}, Unemployment rate: {unemployment_rate_value}"
for poverty_rate_value, unemployment_rate_value
in zip(poverty_rate, unemployment_rate
]
markers = gmaps.marker_layer(marker_locations, info_box_content)
请注意,您可以在模板中使用任意 HTML,这样您就可以很好地格式化您的字符串。有关示例,请参阅 the tutorial on markers。