首页 > 解决方案 > 尝试加载数据并返回 GeoDataFrame,出现错误

问题描述

对于一个挑战,我正在尝试编写一个函数,该函数将形状文件的文件名和 CSV 的文件名作为参数。CTIDFP00我希望它在名为和CensusTract(分别)的列中合并两个文件。

我希望该函数返回一个 GeoDataFrame。这是我目前的程序:

def loading_data(shapefile, csvfile): merged = shapefile.merge(csvfile, left_on='CTIDFP00', right_on='CensusTract') print(load_in_data('filepath','otherfilepath'))

但它返回错误AttributeError: 'str' object has no attribute 'merge'

在这种情况下我该如何解决这个问题?我一直在试图弄清楚近两个小时。

标签: pythonpandasgeopandas

解决方案


您需要在合并它们之前加载数据框。

def loading_data(shapefile, csvfile):
df1 = #load the shapefile
df2 = #load the csvfile 
merged = df1.merge(df2, left_on='CTIDFP00', right_on='CensusTract') 

print(load_in_data('filepath','otherfilepath'))


推荐阅读