how to use groupby to avoid loop in python,df.ix[idx]