【发布时间】:2019-05-22 20:05:47
【问题描述】:
我有数据框,其中有两个字符串列,需要连接到单个列
2 列中有 3 个值。
1.Column Comment_vol由Blank、Pass和VolA组成
2.Column Comment_wt 由 wtA,Pass 组成
现在我需要一个列,
当Comment_vol 列有空白,且Comment wt 列有任何值时,comment_wt 列取值,vise vsersa
当两列值都有Pass时,应该取Pass
如果同时有 VolA 和 wtA,则应该两者兼得
输入:
Comment_vol Comment_wt
Pass wtA
Pass
VolA Pass
Pass Pass
wtA
VolA wtA
输出:
Comment_vol Comment_wt Comment_final
Pass wtA wtA
Pass Pass
VolA Pass VolA
Pass Pass Pass
wtA wtA
VolA wtA VolA, WtA
代码:
df['Comment'] = df['comment_vol'].str.cat(df['comment_wt'], sep =" ")
【问题讨论】:
标签: python-3.x pandas dataframe concatenation