![](/img/trans.png)
[英]How to join two dataframe on different columns without using index
[英]How to join two different dataframe whit different index
早上好,我想加入兩個不同的 DataFrame,但它們有不同的索引(如下圖所示)。 事實上,第一個是 train_test_split 的結果,第二個是轉換為 DataFrame 的數組。 第一個 ( new_features
) 是一個 1700x21 的數據幀,第二個 ( y_test_pred_new
) 是一個 1700x1 的數據幀。 如何在不注意索引的情況下將第二個(1700x1)添加到第一個 DataFrame? 所以,簡單地采取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'])
我試圖這樣做,但它不起作用。
new_dataset = pd.concat([new_features, y_test_pred_new], axis= 1)
您可以使用 append 而不是 concat,但您必須保留大數據幀的索引
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.