I have a dataframe containing 3 columns. I want to subtract the last entry of col2 from second to last entry of col2 and see if the subtraction of last from second to last entry is greater than 10 difference. If so, I would like to get the corresponding value for last and second to last in first column and replace the value of second to last in first column with 'NaN', and create another dataframe as output. Is there any way i can do it in pandas?

col1  col2   col3
 a      21      1
 b      20      1
 c      9       1
 d      20      1

Output:

 col1         col3   
 [d, 'NaN']    1

Thanks in advance.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.