小编Ian*_*yce的帖子

为什么Pandas内连接会产生ValueError:len(left_on)必须等于"right"索引中的级别数?

我正在尝试将DataFrame A内部连接到DataFrame B并遇到错误.

这是我的连接声明:

merged = DataFrameA.join(DataFrameB, on=['Code','Date'])
Run Code Online (Sandbox Code Playgroud)

这是错误:

ValueError: len(left_on) must equal the number of levels in the index of "right"
Run Code Online (Sandbox Code Playgroud)

我不确定列顺序是否重要(它们不是真正"有序"的吗?),但为了以防万一,DataFrames组织如下:

DataFrameA:  Code, Date, ColA, ColB, ColC, ..., ColG, ColH (shape: 80514, 8 - no index)
DataFrameB:  Date, Code, Col1, Col2, Col3, ..., Col15, Col16 (shape: 859, 16 - no index)
Run Code Online (Sandbox Code Playgroud)

我需要更正我的加入声明吗?或者是否有另一种更好的方法来获得这两个DataFrame的交集(或内连接)?

python merge join inner-join pandas

52
推荐指数
2
解决办法
5万
查看次数

标签 统计

inner-join ×1

join ×1

merge ×1

pandas ×1

python ×1