我試圖從Google Maps JavaScript API v3使用熱圖可視化服務。CSV字段導入格式問題
我有一個帶有lat,lng和weight的csv文件。它看起來像這樣:
lat, lng, weight
37.782551, -122.445368, 1
51.520027, -0.0923842, 2
我希望得到來自這些CSV值 -
{location: new google.maps.LatLng(37.782551,-122.445368), weight: 1},
{location: new google.maps.LatLng(51.520027,-0.0923842), weight: 2},
我沒有JavaScript的知識以下結果,所以我嘗試使用Python。
with open('./Test.csv', 'rU') as csvfile:
reader = csv.DictReader(csvfile)
location = ['{lat},{lng}'.format(**row) for row in reader]
weight = ['weight'.format(**row) for row in reader]
for i in range(0,(len(location))):
location_lt = ("new google.mapsLatLng", location[i])
location_we = (location_lt, "weight", weight)
print(location_we)
但是,這有很多問題。重量字段丟失。我相信我應該嘗試使用zip功能。格式也不如上
(('new google.mapsLatLng', '51.5195078,-0.0971911'), 'weight', [])
(('new google.mapsLatLng', '51.520027,-0.0923842'), 'weight', [])
任何指針將不勝感激。
偉大的解決方案,甚至更好的解釋,謝謝! – LearningSlowly 2015-03-04 08:42:18
謝謝!很高興它是有幫助的! – 2015-03-04 15:00:42