Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = {'A':[1,2,5,7,0,9],
- 'B':[6,5,0,0,7,2],
- 'C':[0,8,np.nan,10,0,6],
- 'D':[np.nan, 9,5,2,6,7],
- 'E':[1,4,6,3,3,6]}
- aidx = ['id_1','id_2','id_3',
- 'id_4','id_5','id_6']
- df = pd.DataFrame(a, index=aidx)
- def get_col(df,num):
- df_num = df==num
- df_num=df_num[df_num.any(axis=1)].idxmax(axis=1)
- return(df_num)
- df_new = pd.DataFrame(get_col(df,0))
- df_need = pd.DataFrame([2,999,1,1,0,999], index=aidx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement