I know to cast pandas DataFrame column to a list (with .tolist()
or list()
) and then do what you want, will make it way much slower, so I don't want to use these methods.
I want to find the index of the first element of a pandas DataFrame column which is equal or greater than a value x
, in other words >=x
. And if there is nothing then return None
.
For example, if the column is this and our function is called first_greater()
:
0
0 1
1 -5
2 6
3 4
4 -7
5 12
6 -2
7 0
8 -3
Then we have:
first_greater(-5) = 0
first_greater(7) = 5
first_greater(4) = 2
first_greater(6) = 2
first_greater(22) = None
I'm new to pandas and I don't know how to do this. Any help would be appreciated.