美文网首页
ValueError: Shape of passed valu

ValueError: Shape of passed valu

作者: 遥远的清平湾 | 来源:发表于2019-03-21 10:54 被阅读0次

原创。转载请注明出处。

  • 关于pandas合并dataframe错误

问题描述

执行下面代码时引起 ValueError: Shape of passed values is (r1, c1), indices imply (r1, c2) 错误(注:r1、c1、c2为整数,c1 != c2):

pd.concat([df1, df2], axis=1, join='outer')

错误原因

df1或df2中存在重复的index,导致合并时发生逻辑冲突

解决方法

df1 = df1.loc[df1.index.drop_duplicates(keep=False),:] # 去掉df1中重复索引
df2 = df2.loc[df2.index.drop_duplicates(keep=False),:] # 去掉df2中重复索引
pd.concat([df1, df2], axis=1, join='outer')

相关文章

网友评论

      本文标题:ValueError: Shape of passed valu

      本文链接:https://www.haomeiwen.com/subject/ittqvqtx.html