Pandas dataframe "power" has datetime as index. Columns are Ap1, Ap2, Ap3 and Solar that have float64 values. However, some of the data is bad and I want to replace all values over a certain value (e.g. 100 000) with zero. Here's how the dataframe looks:
power.head()
power.describe()
Ap1 Ap2 Ap3 Solar
Datetime
2018-01-01 00:00:00 659.18 59.51 120.39 0.0
2018-01-01 00:01:00 600.59 119.93 179.90 0.0
2018-01-01 00:02:00 600.59 119.93 119.93 0.0
2018-01-01 00:03:00 534.67 119.93 59.97 0.0
2018-01-01 00:04:00 600.59 119.93 119.93 0.0
Ap1 Ap2 Ap3 Solar
max 6.489067e+06 1.167420e+06 2.296201e+06 52433.040000
I'm trying to go through the columns with an if function that would replace the large values with a zero:
def badvalue(x):
if x > 100000:
x == 0
power["Ap1"].apply(badvalue)
However, this does nothing to the data, and I understand you probably can't change the values this way anyway (I wish Pandas was this intuitive though!). So what is the easiest/best way to do this with Pandas?
And if I wanted to do this for all columns at the same time instead of just one column, would the method be something different?
Thank you for your help.