Question: i have a dataframe as below.

```
test = pd.DataFrame({'col1':[0,0,1,0,0,0,1,2,0], 'col2': [0,0,1,2,3,0,0,0,0]})
   col1  col2
0     0     0
1     0     0
2     1     1
3     0     2
4     0     3
5     0     0
6     1     0
7     2     0
8     0     0

```

For each column, i want to find the index of value 1 before the maximum of each column. For example, for the first column, the max is 2, the index of value 1 before 2 is 6. for the second column, the max is 3, the index of value 1 before the value 3 is 2. 

In summary, I am looking to get [6, 2] as the output for this test DataFrame. Is there a quick way to achieve this?

Answer: 
Here's a mixed `numpy` and `pandas` solution:

```
(test.eq(1) & (test.index.values[:,None] < test.idxmax().values)).cumsum().idxmax()

```

which is a bit faster than the other solutions.
I would use `dropna` with `where` to drop duplicated `1` keeping the last `1`, and call `idxmin` on it.

```
test.apply(lambda x: x.where(x[:x.idxmax()].eq(1)).drop_duplicates(keep='last').idxmin())

Out[1433]:
col1    6
col2    2
dtype: int64

```