给定一个DataFrame df,我想做类似的事情:
if df['one'] >= df['two']:
df['three'] = df['four']
df['five'] = df['two'] / df['four']
答案 0 :(得分:3)
将.loc
属性与布尔索引一起使用。
condition = df.one >= df.two
df.loc[condition, 'three'] = df['four']
df.loc[condition, 'five'] = df['two'] / df['four']