如果值存在于另一列中,则更改列值

Change Column Value if Value Exists In Another Column

给定以下 pandas df -

Holding Account Account Type Column A Column B
Rupert 06 (23938996) Holding Account 1825973 1702598
Rupert 07 (23938996) Holding Account 1697870 1825973
- - - -
Caroline 06 (0131465) Holding Account 11112222 5435450
Caroline 07 (0131465) Holding Account 7896545 11112222

我正在尝试找到一种方法来执行以下操作 -

这意味着 pandas df 现在看起来如下 -

Holding Account Account Type Column A Column B
Rupert 06 (23938996) Holding Account 1825973 1702598
Rupert 07 (23938996) Holding Account 1697870 1702598
- - - -
Caroline 06 (0131465) Holding Account 11112222 5435450
Caroline 07 (0131465) Holding Account 7896545 5435450

有没有人对我如何实现这样的结果有一些建议?

有用信息:

请试试这个:

import numpy as np
df['Column B'] = np.where(df['Column B'].isin(df['Column A'].values),df['Column B'].shift(),df['Column B'])