1import pandas as pd
2import numpy as np
3
4df = pd.DataFrame({'value':np.arange(1000000)})
5
6# Solution 1 - Fastest :
7df['value'] = np.where(df['value'] > 20000, 0, df['value'])
8
9# Solution 2:
10df.loc[df['value'] > 20000, 'value'] = 0
11
12# Solution 3:
13df['value'] = df['value'].mask(df['value'] > 20000, 0)
14
15# Solution 4 - Slowest, note that df.where applies where condition is wrong:
16df['a'] = df.where(df.a <= 20000, 0)
17