Python Pandas concat函数给出ValueError:传递值的形状为{passed},索引暗示{implied}
concat线给出 raise VALUERROR(f)传递值的形状为{passed},索引暗示 {implied}”)ValueError:传递值的形状为(18585,6),索引 暗示(12390,6) 我不明白为什么上面写着18585。还有其他连接方法吗?请帮忙 编辑: 我想我找到了问题所在 打印结果给了我以下信息Python Pandas concat函数给出ValueError:传递值的形状为{passed},索引暗示{implied},python,python-3.x,pandas,dataframe,valueerror,Python,Python 3.x,Pandas,Dataframe,Valueerror,concat线给出 raise VALUERROR(f)传递值的形状为{passed},索引暗示 {implied}”)ValueError:传递值的形状为(18585,6),索引 暗示(12390,6) 我不明白为什么上面写着18585。还有其他连接方法吗?请帮忙 编辑: 我想我找到了问题所在 打印结果给了我以下信息 result = df1.append(df2) finalDf = pd.concat([principal_Df, result[['label']]], axis=1)
result = df1.append(df2)
finalDf = pd.concat([principal_Df, result[['label']]], axis=1)
print(principal_Df.shape) //gives (12390, 5)
print(result.shape) // gives (12390, 9)
印刷原理图
label
0 1.0
1 1.0
2 1.0
3 1.0
4 1.0
...
6190 0.0
6191 0.0
6192 0.0
6193 0.0
6194 0.0
[12390 rows x 1 columns]
结果Df最初是通过添加两个Df获得的
principal component 1 ... principal component 5
0 -3.815308 ... -0.921742
1 -0.192024 ... -0.449291
2 -1.755755 ... 0.603834
3 -0.663780 ... 0.711707
4 1.288255 ... 1.115953
... ... ...
12385 0.819819 ... 0.534367
12386 1.343206 ... 0.153296
12387 2.327933 ... -1.012771
12388 -0.180687 ... -0.048978
12389 -0.240281 ... -0.042431
[12390 rows x 5 columns]
行号不是从0到12390的延续,而是从0到6194,并在0到6194处重新启动。这可能是问题所在吗?
如何获取结果的行索引以继续df.append?我计算了一下。我必须执行
result=df1.append(df2,ignore_index=True)
,然后它将继续索引。问题已解决。结果[['label']]
这可能是双重[]
导致的问题是打字错误,但事实并非如此。改变没有帮助。
result = df1.append(df2)