[英]How to merge two matrix(DataFrame) with different row size and same column size?
嗨,我剛開始使用 python,我遇到了這樣的問題。 我從.csv加載了我的數據集,然后我只在兩個不同的變量中保存了那些第 0 列值等於 3 或 5 的候選者(以免將它們leafs_three
和leafs_five
)。 然后我想將這些leafs_three
, leafs_five
合並為一個leafs_three_and_five
,但實際上我不知道我該怎么做。
leafs_three
和leafs_five
大小:
leafs_three
是一個[10 行 x 16 列]矩陣leafs_five
是一個[12 行 x 16 列]矩陣這些矩陣的類型是pandas.core.frame.DataFrame
。 我想通過合並leafs_three
和leafs_five
來獲得一個[22 行 x 16 列]矩陣
我試過的:
leafs_three_and_five = np.concatenate((leafs_three, leafs_five))
leafs_three_and_five = pd.merge(leafs_three, leafs_five)
作為 np.concatenate 的結果,我得到了數組的數組
作為 pd.merge 的結果,我得到了空的 DataFrame
要連接您通過pd.read_csv
方法加載了庫pandas的矩陣,您應該使用pandas提供的另一種方法。 此方法是pd.concat
,它采用要合並的 DataFrame 數組。 例如
pd.concat([data_frame_a, data_frame_b])
要閱讀有關此方法的更多信息,請訪問此鏈接: pandas concat
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.