【发布时间】:2019-02-08 23:54:56
【问题描述】:
我有一个数据框:
df
col1 col2
1 True False
2 True True
3 False False
4 False True
我想创建一个新列,如果布尔值相等,则返回 False,如果它们不同,则返回 True。
类似:
df['col3'] = False if df['col1'] == df['Col2'] else True
df
col1 col2 col3
1 True False True
2 True True False
3 False False False
4 False True True
谢谢。
【问题讨论】:
标签: python pandas dataframe boolean boolean-logic