Replace values in Pandas Series Given Condition
问题 This is a trivial question that I just have not been able to find a clear answer on: I have a Series object: random = pd.Series(np.random.randint(10, 10))) I want to replace all values greater than 1 with 0. How do I do this? I've tried Random.replace() without success and I know you can do this easily in a DataFrame, but how do I do it in a Series object? 回答1: Why not just try to set s[s > 1] = 0 import pandas as pd import numpy as np # your data # ============================ np.random.seed