pandas concat产生ValueError:平面形状未对齐 [英] Pandas concat yields ValueError: Plan shapes are not aligned

查看:238
本文介绍了 pandas concat产生ValueError:平面形状未对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对熊猫还很陌生,我试图连接一组数据框,但出现此错误:

I am quite new to pandas, I am attempting to concatenate a set of dataframes and I am getting this error:

ValueError: Plan shapes are not aligned

我对.concat()的理解是,它将在列相同的地方连接,但对于找不到的列将使用NA填充.这里似乎不是这种情况.

My understanding of .concat() is that it will join where columns are the same, but for those that it can't find it will fill with NA. This doesn't seem to be the case here.

在此处显示concat语句:

Heres the concat statement:

dfs = [npo_jun_df, npo_jul_df,npo_may_df,npo_apr_df,npo_feb_df]
alpha = pd.concat(dfs)

推荐答案

如果有帮助,当我尝试连接两个数据帧时,我也会遇到此错误(而在撰写本文时,这是唯一相关的命中我可以在Google上找到源代码以外的其他代码).

In case it helps, I have also hit this error when I tried to concatenate two data frames (and as of the time of writing this is the only related hit I can find on google other than the source code).

我不知道此答案是否可以解决OP的问题(因为他/她没有发布足够的信息),但是对我来说,这是由于我尝试使用列对concat数据帧df1造成的['A', 'B', 'B', 'C'](请参见重复的列标题?),数据框为df2,列为['A', 'B'].可以理解的是,重复导致大熊猫晃动.将df1更改为['A', 'B', 'C'](即删除重复的列之一),一切正常.

I don't know whether this answer would have solved the OP's problem (since he/she didn't post enough information), but for me, this was caused when I tried to concat dataframe df1 with columns ['A', 'B', 'B', 'C'] (see the duplicate column headings?) with dataframe df2 with columns ['A', 'B']. Understandably the duplication caused pandas to throw a wobbly. Change df1 to ['A', 'B', 'C'] (i.e. drop one of the duplicate columns) and everything works fine.

这篇关于 pandas concat产生ValueError:平面形状未对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆