SHARE
TWEET

Untitled

a guest Jun 27th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. a = {'A':[1,2,5,7,0,9],
  2.      'B':[6,5,0,0,7,2],
  3.      'C':[0,8,np.nan,10,0,6],
  4.      'D':[np.nan, 9,5,2,6,7],
  5.      'E':[1,4,6,3,3,6]}
  6. aidx = ['id_1','id_2','id_3',
  7.         'id_4','id_5','id_6']
  8. df = pd.DataFrame(a, index=aidx)
  9.      
  10. def get_col(df,num):
  11.     df_num = df==num
  12.     df_num=df_num[df_num.any(axis=1)].idxmax(axis=1)
  13.     return(df_num)
  14. df_new = pd.DataFrame(get_col(df,0))
  15.      
  16. df_need = pd.DataFrame([2,999,1,1,0,999], index=aidx)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top