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)
字符串
concat线给出了
raise ValueError(f“Shape of passed values is {passed},indices imply {implied}”)ValueError:Shape of passed values is(18585,6),indices imply(12390,6)
我不明白为什么它说18585。有没有其他方法连接?请帮助。
答:我想我找到问题了。
打印结果给我以下
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]
型
并且打印principal_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]
型
结果Df最初是通过追加两个df得到的
result = df1.append(df2)
型
而且行号不是从0到12390的连续,而是从0到6194,然后从0到6194重新开始。这可能是问题所在吗?我如何让result的行索引在df.append上继续?
1条答案
按热度按时间hujrc8aj1#
我算到了。我必须做
result = df1.append(df2, ignore_index=True)
,然后它会继续索引。问题解决了。