-1

I am trying to get the pop-up box in Gmaps to show information from two different lists. When I use 'and' to combine my info_box_content only unemployment rate show in the pop-up. When I comment out the second list (as shown) the poverty rate info shows. Is this possible?

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

screenshot

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Dan K
  • 3
  • 1
  • Does this answer your question? [How do I concatenate two lists in Python?](https://stackoverflow.com/questions/1720421/how-do-i-concatenate-two-lists-in-python) – MrUpsidown Jun 28 '20 at 12:44
  • 1
    Maybe a complete demo could help to understand the behavior better. – perelin Jun 28 '20 at 20:54

1 Answers1

1

The info_box parameter takes a list with a string for each marker. You can create that string however you want. For instance, you could write:

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)

Note that you can use arbitrary HTML in the template, so you can format your string nicely. See the tutorial on markers for examples.

Pascal Bugnion
  • 4,878
  • 1
  • 24
  • 29