python - Python Pandas:TypeError:只能将整数标量数组转换为标量索引
问题描述
我目前正在尝试将 shapefile 与 csv 合并。不幸的是,我的代码不起作用,因为我收到以下错误:
---> 17 merged = gdf.merge(df, left_on = 'ID', right_on = 'ID')
TypeError: only integer scalar arrays can be converted to a scalar index
我的代码如下:
shapefile ='C:/Users/User/Desktop/Shapefile/Stadtteil.shp'
gdf = gpd.read_file(shapefile)[['ID2', 'ID2FLOAT' , 'Shape_Leng' , 'Shape_Area']]
gdf.columns = [['ID','IDFLOAT','Shape_Leng' , 'Shape_Area']]
gdf.head()
import pandas as pd
datafile = 'C:/Users/User/Desktop/Stadtteile3.csv'
df = pd.read_csv(datafile, names = ['ID','Einwohner'], skiprows = 1)
df.columns = df.columns.get_level_values(0)
df.head()
merged = gdf.merge(df, left_on = 'ID', right_on = 'ID')
#---------------------------------------------------------
# I also tried the following:
#df['ID']=df['ID'].astype(int)
#gdf = gdf.astype(int)
#gdf['ID']=gdf['ID'].astype(int)
#import numpy as np
#x=np.concatenate(gdf['ID'],df['ID'])
#---------------------------------------------------------
数据文件如下:
太感谢了!
解决方案
推荐阅读
- android - 如何在 mac high sierra 上修复这个 android studio 错误?
- laravel - 安装问题
- python - “Animal”的“foo”没有重载变体匹配参数类型“str”
- sql - 将 SQL 登录迁移到隔离环境
- html - Google 协作平台内部链接
- python - 我有一个长度不同的元组列表,所以我需要遍历列表
- perl - 无法在 Perl 5.32.0 MacOS Sierra 上安装 Test::File
- visual-studio-code - VSCode 无法识别所有 .clang-format 选项
- python - Pandas_ta - NoneType 对象没有属性副本
- javascript - 测验中的按钮侦听器 - 旧侦听器产生错误的输出