我有2行看起来像这样,
------------------------------
DealName | Target | Acquirer |
-----------------------------
ABC-XYZ | ABC | None |
------------------------------
ABC-XYZ | None | XYZ |
------------------------------
我希望将它们合并为一个:
------------------------------
DealName | Target | Acquirer |
-----------------------------
ABC-XYZ | ABC | XYZ |
------------------------------
不确定如何在Pandas中完成此操作。任何指针将不胜感激!预先感谢
答案 0 :(得分:6)
IIUC
df.replace('None','').groupby('DealName',as_index=False).agg(''.join)
Out[25]:
DealName Target Acquirer
0 ABC-XYZ ABC XYZ