【问题标题】:Python Geopandas Module Object Not CallablePython Geopandas 模块对象不可调用
【发布时间】:2020-06-30 23:27:12
【问题描述】:

我正在尝试使用 geopandas 在地图上绘制 x、y 或纬度和经度点,但出现此错误:

File "C:\Users\U321103\.spyder-py3\Plot90thPercentile_MKTest_maps.py", line 
19, in <module>
gdf = gdf(dfp, geometry=geometry)
TypeError: 'module' object is not callable

我的代码如下所示:

from sys import exit
from shapely.geometry import Point
import geopandas as gpd
from geopandas import geodataframe as gdf
from shapely.geometry import Point, LineString
import pandas as pd


dfp = pd.read_csv("\\\porfiler03\\gtdshare\\Long_Lats_90p.csv", 
delimiter=',', skiprows=0, 
low_memory=False)
geometry = [Point(xy) for xy in zip(dfp['Longitude'], dfp['Latitude'])]
gdf = gdf(dfp, geometry=geometry)   

#this is a simple map that goes with geopandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
gdf.plot(ax=world.plot(figsize=(10, 6)), marker='o', color='green', 
markersize=15);
exit()

我得到的错误在第 19 行:

gdf = gdf(dfp, geometry=geometry) 

我认为该错误可能与第 19 行的某些内容不是“可调用”且必须是“gdf”有关,但我不确定如何解决此问题。最终,我需要一张地图,其中包含我文件中的点,以便在世界地图上显示为红点。我的 df "dfp" 看起来像这样 - 谢谢你的帮助!

   Longitude  Latitude
0    -76.124    40.853
1    -96.063    44.065
2     -3.480    43.140
3     -2.060    38.750
4     -2.420    38.880

【问题讨论】:

    标签: python plot mapping geopandas


    【解决方案1】:

    您正在尝试导入 geopandas.GeoDataFrame 类,但正在导入 geopandas.geodataframe 模块。请记住,Python 区分大小写。

    from geopandas import GeoDataFrame as gdf
    

    【讨论】:

    • 谢谢 - 但是当我按照你的建议尝试在导入中更改“GeoDataFrame”时,我收到此错误 - ImportError: cannot import name 'GeoDataFrame' from 'geopandas' (unknown location) - 但是当我更改为“geodataframe”然后它不会显示错误。
    • 简单的解决方案是使用gpd.GeoDataFrame,而不是单独导入。
    • 好的,当我尝试定义“world”变量时,我只使用“gpd”一次。它将如何在我上面的代码中使用它?我的错误是在第 19 行使用“gpd”之前。
    • gdf = gpd.GeoDataFrame(dfp, geometry=geometry)
    【解决方案2】:

    看起来这是安装“geopandas”的问题。我已经删除然后重新安装了这个包,并且没有发生错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2017-01-12
      • 2021-06-12
      • 1970-01-01
      相关资源
      最近更新 更多