I have the following dataframe and list of values:
df = pd.DataFrame({"A": [1, 4, 6, 2, 7, 4]}, index=pd.date_range(start='1/1/2020', end='1/06/2020'))
values_to_find = [4, 6, 2]
A
2020-01-01 1
2020-01-02 4
2020-01-03 6
2020-01-04 2
2020-01-05 7
2020-01-06 4
I want to get the index (iloc) of the first value 4 in the dataframe if the next two rows in the dataframe has values 6 and 2. In this case, the desired output is 2 as it is the second index (iloc) in the dataframe.
I tried using np.flatnonzero(df['A'] == values_to_find)
but np.flatnonzero()
only works with a single value, otherwise values_to_find
must be of the same size as the dataframe.