熊猫包含替换公式

时间:2020-06-08 01:52:11

标签: python pandas

我无法获得if语句在2列上工作

到目前为止的进展:

col1= example.com/abc/abs

目标:获取最后"/"之后的内容的输出

这有效:

df['col2'] = df['col1'].str.rsplit('/', 1, expand=True)[1]

这部分我需要帮助:

如果col2包含"/",那么我想用col1替换它,否则将col1保留不变。

我尝试了但没用:

df1['col1'] = np.where(df1['col2'] =="/" , df1['col2'], df1['col1'])

1 个答案:

答案 0 :(得分:0)

编辑:

df['col1'] = numpy.where(df['col2'].notna(), df['col2'], df['col1'])
相关问题