简体   繁体   English

如何加入具有不同索引的两个不同数据帧

[英]How to join two different dataframe whit different index

Good morning, I want to join two different DataFrame, but they have different index (As you can see in the picture below).早上好,我想加入两个不同的 DataFrame,但它们有不同的索引(如下图所示)。 Infact, the first is the result of a train_test_split and the second is an array converted into a DataFrame.事实上,第一个是 train_test_split 的结果,第二个是转换为 DataFrame 的数组。 The first ( new_features ) is a DataFrame 1700x21 and the second ( y_test_pred_new ) is a DataFrame 1700x1.第一个 ( new_features ) 是一个 1700x21 的数据帧,第二个 ( y_test_pred_new ) 是一个 1700x1 的数据帧。 How can I add the second one (1700x1) to the first DataFrame without pay attention to the index?如何在不注意索引的情况下将第二个(1700x1)添加到第一个 DataFrame? So Simply taking the 1700x1 and add it as the 22° columns in new_features .所以,简单地采取1700x1并将其添加为在22°列new_features

new_features = pd.concat([X_test3, features_post_test], axis = 1)
y_test_pred_new = pd.DataFrame(y_test_pred,columns = ['Soot_EO_pred'])

I tried to do in this way but it doesn't work.我试图这样做,但它不起作用。

new_dataset = pd.concat([new_features, y_test_pred_new], axis= 1)

在此处输入图片说明 在此处输入图片说明

您可以使用 append 而不是 concat,但您必须保留大数据帧的索引

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM