I have a dataframe like as shown below
stud_id prod_id total_qty ques_date inv_qty inv_date bkl_qty bkl_date csum accu_qty accu_date upto_inv_threshold upto_bkl_threshold upto_accu_threshold
0 101 12 100 13/11/2010 7.00000 16/02/2012 15 2013-01-16 15 10 13/08/2021 7.00000 22.00000 32.00000
1 101 12 100 13/11/2010 7.00000 16/02/2012 40 2011-10-22 55 10 13/08/2021 7.00000 62.00000 72.00000
2 101 12 100 13/11/2010 7.00000 16/02/2012 2 2019-09-10 57 10 13/08/2021 7.00000 64.00000 74.00000
df = pd.read_clipboard()
I would like to do the two steps listed below
step-1) search for values >=50 in a dataframe and return only the 1st occurrence.
Do the above search only in 3 columns - upto_inv_threshold, upto_bkl_threshold, upto_accu_threshold but column wise. Meaning, complete the search in one column first and then move to the next column. Ex: we search all values of upto_inv_threshold first, then we search all values of upto_bkl_threshold, later/finally we search all values of upto_accu_threshold
step-2) Get the corresponding date for that 1st occurrence value found in step 1. If the value is found upto_inv_threshold, get the inv_date. If the 1st occurrence value is found in upto_bkl_threshold, get the bkl_date. If the 1st occurrence value is found in upto_accu_threshold, get the accu_date.
I tried the below
df_stage_3.loc[:, 'upto_inv_threshold':'upto_accu_threshold']
np.where(df_stage_3.loc[:, 'upto_inv_threshold':'upto_accu_threshold']>=50)
but this is going nowhere and am not able to proceed further.
We have to do this for each stud_id and prod_id. Currently, in sample data we have only group but in real data we will have multiple groups of stud_id and prod_id.
I expect my output to be like as shown below. we get the date from bkl_date column because the 1st value (that met our criteria >=50) was 62 (present in upto_bkl_threshold)
stud_id, prod_id, fifty_pct_date
101, 12, 2011-10-22