Iterating In Dataframe And Writing Down The Index Of The Values Where A Condition Is Met
I have a data made of 20 rows and 2500 columns. Each column is a unique product and rows are time series, results of measurements. Therefore each product is measured 20 times and t
Solution 1:
Simply use .gt
+ .idxmax
, which will give you the index of the first time your condition is met.
import pandas as pd
import numpy as np
np.random.seed(12)
df = pd.DataFrame(np.random.randint(1,5,(20,2500)))
df.gt(3).idxmax()
#0 0
#1 0
#2 4
#3 4
#4 1
#...
#2496 8
#2497 0
#2498 5
#2499 1
Post a Comment for "Iterating In Dataframe And Writing Down The Index Of The Values Where A Condition Is Met"