【发布时间】:2021-09-17 07:12:26
【问题描述】:
嗨,对于每个分组(基于动物和颜色),我想在检查列中检查 Action = 'See' 是否为 'No'。如果 Action = 'See' 为 'No',则 Check 列中的特定分组将是 'No'。
如果 Action = See and Check = Yes,则保持旧值(参考 Tiger, White)
animallist= df['Animal'].unique().tolist()
colourlist= df['Colour'].unique().tolist()
for i in animallist:
for j in colourlist:
df = df[(df['Animal'] == i) & (df['Colour'] == j)]
df['Check'] = np.where((df['Action'] == 'See') & (df['Check'] == 'no'), 'no',
df['Check'])
【问题讨论】:
标签: python pandas dataframe conditional-statements pandas-groupby