You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Geopandas绘制世界地图时出现GeoDataFrame不可调用错误如何解决

错误原因

TypeError: 'GeoDataFrame' object is not callable报错由代码df = df(['Country', 'Confirmed'])触发:此处误用圆括号()调用GeoDataFrame对象,pandas/geopandas中筛选指定列的正确语法为使用方括号[]。

修正代码

df = gpd.read_file("world-polygon.shp")
df.head()

# 替换圆括号为方括号筛选列
df = df[['Country', 'Confirmed']]

data_for_map = df.rename(index=str, columns={'Country':'Regions','Confirmed':'Conf'})
data_for_map.head()

补充说明

若后续需要使用该数据绘制地图,筛选列时需保留geometry几何列,否则会缺失绘图所需的空间信息,对应调整为:

df = df[['Country', 'Confirmed', 'geometry']]

内容的提问来源于stack exchange,提问作者Aryan Thakur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 02:06:04