简体   繁体   中英

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). Infact, the first is the result of a train_test_split and the second is an array converted into a DataFrame. The first ( new_features ) is a DataFrame 1700x21 and the second ( y_test_pred_new ) is a DataFrame 1700x1. How can I add the second one (1700x1) to the first DataFrame without pay attention to the index? So Simply taking the 1700x1 and add it as the 22° columns in 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,但您必须保留大数据帧的索引

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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