您好我有以下json文件,其中包含拉斯维加斯6000家餐厅的信息,例如:“名称”,“经度”,“纬度”。我想使用“经度”创建地图和地图标签标签,“ “每个点的纬度”并在地图中显示每个餐厅的“名称”。我使用pycharm和python 3.6.5(32位)。我尝试导入folium库,它可以工作,但它不显示名称地图中的每家餐馆。如何在地图中显示每家餐厅的名称?提前致谢!
json文件yelp_restaurant_Las_Vegas是:
{
"_id" : ObjectId("5a9eb7b2a2f96c346024f239"),
"city" : "Las Vegas",
"neighborhood" : "Southeast",
"name" : "Flight Deck Bar & Grill",
"business_id" : "Pd52CjgyEU3Rb8co6QfTPw",
"longitude" : -115.1708484,
"hours" : {
"Monday" : "8:30-22:30",
"Tuesday" : "8:30-22:30",
"Friday" : "8:30-22:30",
"Wednesday" : "8:30-22:30",
"Thursday" : "8:30-22:30",
"Sunday" : "8:30-22:30",
"Saturday" : "8:30-22:30"
},
"state" : "NV",
"postal_code" : "89119",
"categories" : [
"Nightlife",
"Bars",
"Barbeque",
"Sports Bars",
"American (New)",
"Restaurants"
],
"stars" : 4.0,
"address" : "6730 S Las Vegas Blvd",
"latitude" : 36.0669136,
"review_count" : NumberInt(13),
"is_open" : NumberInt(1),
.
.
.
代码为:
from pymongo import MongoClient
import pandas as pd
import folium
from IPython.display import HTML
client = MongoClient("localhost",27017)
db = client.Desktop
collection1 =db.yelp_restaurant_Las_Vegas
reviews=pd.DataFrame(list(collection1.find()))
mapi_osm = folium.Map(location=())
reviews.apply(lambda row:folium.CircleMarker(location[row["latitude"],row["longitude"]]).add_to(mapi_osm),axis=1)
mapi_osm.save('spst.html')
答案 0 :(得分:0)
将弹出窗口添加到标记中。
如果你想让它们自动打开,你需要来自github的最新的folium(因为pypi上的版本不够新)。几周前,通过show参数支持传单的openPopup调用。如果您不关心它们是否被自动打开则无关紧要(只需删除Popup构造函数的show参数)。
pip install git+https://github.com/python-visualization/folium.git
reviews.apply(lambda row:folium.CircleMarker( location=[row["latitude"],row["longitude"]], popup=Popup(row['name'],show=True)).add_to(mapi_osm),axis=1)
这是一个最小的例子:
import folium from folium.map import Popup m = folium.Map(location=()) folium.CircleMarker(location=(36.112625, -115.176704), popup=Popup('Picasso', show=True)).add_to(m) m.save('map.html')