Search code examples
pythonpandasloopspandas-loc

interacting over a dateframe with functions


if I have a date frame like this: N

EG_00_04  NEG_04_08  NEG_08_12  NEG_12_16  NEG_16_20  NEG_20_24  \
datum_von                                                                      
2017-10-12      21.69      15.36       0.87       1.42       0.76       0.65   
2017-10-13      11.85       8.08       1.39       2.86       1.02       0.55   
2017-10-14       7.83       5.88       1.87       2.04       2.29       2.18   
2017-10-15      14.64      11.28       2.62       3.35       2.13       1.25   
2017-10-16       5.11       5.82      -0.30      -0.38      -0.24      -0.10   
2017-10-17      12.09       9.61       0.20       1.09       0.39       0.57 

And I wanna check the values that are above 0 and change them to zero when they are lower.

Not sure how should I use the function iterrows() and the loc() function to do so.


Solution

  • clip_lower and mask solutions are good.

    Here is another one with applymap:

    df.applymap(lambda x: max(0.0, x))