3
我有三個熊貓dataframes,df1
,df2,
和df3
,如下:Python的大熊貓:加入獨特的列值並連接
import pandas as pd
import numpy as np
df1 = pd.DataFrame({'id' : ['one', 'two', 'three'], 'score': [56, 45, 78]})
df2 = pd.DataFrame({'id' : ['one', 'five', 'four'], 'score': [35, 81, 90]})
df3 = pd.DataFrame({'id' : ['five', 'two', 'six'], 'score': [23, 66, 42]})
我如何加入基於id
這些dataframes然後拼接他們列在一起?所需的輸出如下:
#join_and_concatenate by id:
id score(df1) score(df2) score(df3)
one 56 35 NaN
two 45 NaN 66
three 78 NaN NaN
four NaN 90 NaN
five NaN 81 23
six NaN NaN 42
我發現了一個有關page談到有關merge()
,concatenate()
和join()
,但我不知道任何一個給我想要的東西。