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()
,但我不知道任何一个给我想要的东西。