switch pandas dataframe values where condition is true

Solutions on MaxInterview for switch pandas dataframe values where condition is true by the best coders in the world

showing results for - "switch pandas dataframe values where condition is true"
Sam
09 Mar 2016
1>>> df = pd.DataFrame([[1, 25], [4, 40], [7, 45]],
2     index=['cobra', 'viper', 'sidewinder'],
3     columns=['max_speed', 'shield'])
4>>> df
5            max_speed  shield
6cobra               1       25
7viper               4       40
8sidewinder          7       45
9
10>>> df.loc[df['shield'] > 35] = 0
11>>> df
12            max_speed  shield
13cobra               1      25
14viper               4       0
15sidewinder          7       0
16