The Python Oracle

Pandas: Check if column value is smaller than any previous column value

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Darkness Approaches Looping

--

Chapters
00:00 Pandas: Check If Column Value Is Smaller Than Any Previous Column Value
00:34 Accepted Answer Score 9
00:47 Thank you

--

Full question
https://stackoverflow.com/questions/5373...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pandas

#avk47



ACCEPTED ANSWER

Score 9


This should work:

df['diff'] = df['c'] < df['c'].cummax()

Output is just as you mentioned:

    c   diff
0   1  False
1   4  False
2   9  False
3   7   True
4   8   True
5  36  False