我有两个这样的数据帧:
+--+-----------+
|id|some_string|
+--+-----------+
| a| foo|
| b| bar|
| c| egg|
| d| fog|
+--+-----------+
还有这个:
+--+-----------+
|id|some_string|
+--+-----------+
| a| hoi|
| b| hei|
| c| hai|
| e| hui|
+--+-----------+
我想加入他们,像这样:
+--+-----------+
|id|some_string|
+--+-----------+
| a| foohoi|
| b| barhei|
| c| egghai|
| d| fog|
| e| hui|
+--+-----------+
因此,来自第一个数据帧的列some_string
与来自第二个数据帧的列some_string
相连。如果我正在使用
df_join = df1.join(df2,on='id',how='outer')
它会回来的
+--+-----------+-----------+
|id|some_string|some_string|
+--+-----------+-----------+
| a| foo| hoi|
| b| bar| hei|
| c| egg| hai|
| d| fog| null|
| e| null| hui|
+--+-----------+-----------+
有什么办法吗?你知道吗
考虑到要执行外部联接,可以尝试以下操作:
(请注意,some_string1和2是指df1和df2数据帧中的some_string列。我建议您用不同的名称来命名它们,而不是用一些\u字符串来命名相同的名称,这样您就可以调用它们了)
您需要使用^{} 来实现适当的连接。除此之外,您使用
outer
join的方式几乎是正确的。你知道吗您需要检查这两列中是否有人是^{} 或^{} ,然后执行^{} 。你知道吗
相关问题 更多 >
编程相关推荐