How to properly apply a lambda function into a pandas data frame column

前端 未结 2 432
孤街浪徒
孤街浪徒 2020-12-13 00:26

I have a pandas data frame, sample, with one of the columns called PR to which am applying a lambda function as follows:

sample[\'P         


        
2条回答
  •  醉话见心
    2020-12-13 01:18

    You need to add else in your lambda function. Because you are telling what to do in case your condition(here x < 90) is met, but you are not telling what to do in case the condition is not met.

    sample['PR'] = sample['PR'].apply(lambda x: 'NaN' if x < 90 else x) 
    

提交回复
热议问题