1

In the dataframe below, I want to set row values in the column p50 to NaN if they are below 2.0 between the dates May 15th and August 15th 2018.

                  date       p50
2018-03-02 2018-03-02       NaN
2018-03-03 2018-03-03       NaN
2018-03-04 2018-03-04  0.022590
2018-03-05 2018-03-05       NaN
2018-03-06 2018-03-06 -0.042227
2018-03-07 2018-03-07       NaN
2018-03-08 2018-03-08       NaN
2018-03-09 2018-03-09 -0.028646
2018-03-10 2018-03-10       NaN
2018-03-11 2018-03-11 -0.045244
2018-03-12 2018-03-12       NaN
2018-03-13 2018-03-13       NaN
2018-03-14 2018-03-14 -0.020590
2018-03-15 2018-03-15       NaN
2018-03-16 2018-03-16 -0.028317
2018-03-17 2018-03-17       NaN
2018-03-18 2018-03-18       NaN
2018-03-19 2018-03-19       NaN
2018-03-20 2018-03-20       NaN
2018-03-21 2018-03-21       NaN
2018-03-22 2018-03-22       NaN
2018-03-23 2018-03-23       NaN
2018-03-24 2018-03-24 -0.066800
2018-03-25 2018-03-25       NaN
2018-03-26 2018-03-26 -0.104135
2018-03-27 2018-03-27       NaN
2018-03-28 2018-03-28       NaN
2018-03-29 2018-03-29 -0.115200
2018-03-30 2018-03-30       NaN
2018-03-31 2018-03-31 -0.000455
               ...       ...
2018-07-03 2018-07-03       NaN
2018-07-04 2018-07-04  2.313035
2018-07-05 2018-07-05       NaN
2018-07-06 2018-07-06       NaN
2018-07-07 2018-07-07       NaN
2018-07-08 2018-07-08       NaN
2018-07-09 2018-07-09  0.054513
2018-07-10 2018-07-10       NaN
2018-07-11 2018-07-11       NaN
2018-07-12 2018-07-12  3.711159
2018-07-13 2018-07-13       NaN
2018-07-14 2018-07-14  6.583810
2018-07-15 2018-07-15       NaN
2018-07-16 2018-07-16       NaN
2018-07-17 2018-07-17  0.070182
2018-07-18 2018-07-18       NaN
2018-07-19 2018-07-19  3.688812
2018-07-20 2018-07-20       NaN
2018-07-21 2018-07-21       NaN
2018-07-22 2018-07-22  0.876552
2018-07-23 2018-07-23       NaN
2018-07-24 2018-07-24  1.077895
2018-07-25 2018-07-25       NaN
2018-07-26 2018-07-26       NaN
2018-07-27 2018-07-27  3.802159
2018-07-28 2018-07-28       NaN
2018-07-29 2018-07-29  0.077402
2018-07-30 2018-07-30       NaN
2018-07-31 2018-07-31       NaN
2018-08-01 2018-08-01  3.202214

The dataframe has a datetime index. I do the foll:

mask = (group['date'] > '2018-5-15') & (group['date'] <= '2018-8-15')
group[mask].loc[group[mask]['p50'] < 2.]['p50'] = np.NaN

However, this does not update the dataframe. How to fix this?

1 Answer 1

2

I think you should using .loc like

mask = (group['date'] > '2018-5-15') & (group['date'] <= '2018-8-15')
group.loc[mask&(group['p50'] < 2),'p50']=np.nan
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.