【问题标题】:plotting on googlemaps using pycharm使用 pycharm 在 googlemaps 上绘图
【发布时间】:2021-05-27 23:30:37
【问题描述】:

大家好:) 我是 python 的新手,我被分配了这个我发现不可能弄清楚的任务。我希望这里有人可以帮助我。 我收到了 3 个 excel 文件,其中包含有关欧洲周围空气污染水平的信息(我无法共享这些文件) 我需要在谷歌地图上绘制特定国家(马耳他、意大利、波兰、德国和法国)的坐标和空气污染水平。这是我正在使用的代码:

import gmplot #importing of gmplot
import pandas as pd #importing of pandas

df = pd.read_excel (data_path_eu_2016) #i know this is meant to be a path, however i saved the path 
 in a variable earlieer on in my code so im using the variable name here so that the user will only 
need to insert their path once when using my code
df_lat =df['Latitude'] #picking the latitudes
df_lon =df['Longitude'] #picking of the longitude
df_Country = df['Country']  #i'm including these variables as my assignment instructions says to use 
them though im not sure how to incorporate them in this googlemaps plot
df_City = df['City']
df_AirPollutionLevel = df['AirPollutionLevel']
df_Altitude = df['Altitude']

gmap = gmplot.GoogleMapPlotter(48.925278, 2.356667, 5) #chose a random set of coordinates from one of 
the countries i need to plot data for
gmap.scatter(df_lat[:1000], df_lon[:1000], 'red', size = 10) #Scattering of the coordinates using the 
lat and long list
gmap.draw(r"C:\Users\julia\OneDrive\Documents\python assignment\gmplot_Map.html") #the location where 
the HTML file is to be saved

但是我得到这个错误: 回溯错误:df_lat =df['Latitude'] #picking the latitudes KeyError:“纬度”

我的 excel 文件中存在列名“纬度”,所以我不确定错误是什么?

我将非常感谢任何帮助!

【问题讨论】:

    标签: python pandas pycharm gmplot


    【解决方案1】:

    Pandas 的列名区分大小写。在您的问题中,您声明列名是“纬度”,但是您在脚本中写了“纬度”,所以问题很可能是大写。尝试更改此行:

    df_lat =df['Latitude']

    到这里:

    df_lat =df['latitude']

    我猜同样的问题将持续存在于其他列中,因此请确保验证脚本中的列名与 Excel 文件中的列名完全相同。

    【讨论】:

      猜你喜欢
      • 2011-01-27
      • 2017-02-09
      • 2023-02-19
      • 1970-01-01
      • 2015-07-18
      • 2023-03-13
      • 2017-10-13
      • 2017-07-07
      • 2017-09-27
      相关资源
      最近更新 更多