(Python)以简单的形式连接数据帧

(Python)Joing Dataframes with simple form

我的目标是加入多个 table 并且 3 table 可以像预期的那样连接。

import pandas as pd
df1 = pd.DataFrame({'A':[10,20,30]}, index=[1,2,3])
df2 = pd.DataFrame({'B':[200]}, index=[2])
df3 = pd.DataFrame({'C':[300]}, index=[3])
df1.join(df2).join(df3)

    A      B     C
1  10    NaN    NaN
2  20  200.0    NaN
3  30    NaN  300.0

但是,每当我加入另一个 table 时,如上所述,table 的列会附加到现有列的右侧。 那么,有没有一种像这种简单形式那样加入的巧妙方法呢? (B和C列在一列中表示,列名无关紧要)

    A      
1  10    NaN
2  20  200.0
3  30  300.0 

这个怎么样?

import pandas as pd

pd.concat([df1,df2, df3], axis=1).set_index('A').sum(axis=1)

A
10      0.0
20    200.0
30    300.0
dtype: float64

使用concat-

df1.join(pd.concat([df2, df3.rename(columns={'C': 'B'})]))
#    A      B
#1  10    NaN
#2  20  200.0
#3  30  300.0