python - 尝试加载数据并返回 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'
在这种情况下我该如何解决这个问题?我一直在试图弄清楚近两个小时。
解决方案
您需要在合并它们之前加载数据框。
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'))
推荐阅读
- scala - 如何从 Scala 中的 DataFrame 在 Spark 中创建分布式稀疏矩阵
- angular - 如何在Angular Material中循环聚焦()在扩展面板上?
- sql-server - 按月分组的笨拙方式?
- pointers - 围棋之旅,引用 Vector 结构时 & 和 no & 之间的区别
- mono - Mac 的提琴手:可执行文件中的错误 CPU 类型:mono32
- mysql - mySQL:表的多个来源:拆分与否?
- rxjs - 为什么没有 onComplete() rxjs 运算符?
- android - RecyclerView:在recyclerview中显示标记为收藏的收藏项
- if-statement - 如果单元格为“TRUE”,则 Google 脚本可将单元格的内容更改为选中的复选框
- arm - 如何在 ARM Cortex-A7 上调试 TF-A