Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个 DataFrame df,我想做类似的事情:
if df['one'] >= df['two']: df['three'] = df['four'] df['five'] = df['two'] / df['four']
将.loc属性与布尔索引一起使用。
.loc
condition = df.one >= df.two df.loc[condition, 'three'] = df['four'] df.loc[condition, 'five'] = df['two'] / df['four']