0

给定一个 DataFrame df,我想做类似的事情:

if df['one'] >= df['two']:
    df['three'] = df['four']
    df['five'] = df['two'] / df['four']
4

1 回答 1

3

.loc属性与布尔索引一起使用。

condition = df.one >= df.two
df.loc[condition, 'three'] = df['four']
df.loc[condition, 'five'] = df['two'] / df['four']
于 2013-09-20T21:38:38.013 回答