x=np.array(df.TWD97_x)-Xcenty=np.array(df.TWD97_y)-Ycentix=[max(0,min(nc.NCOLS-1,bisect.bisect_left(x_mesh,xx)-1))forxxinx]iy=[max(0,min(nc.NROWS-1,bisect.bisect_left(y_mesh,yy)-1))foryyiny]df['JI']=[j*tex+ifori,jinzip(ix,iy)]pv=pivot_table(df,index='JI',values='TWD97_x',aggfunc='count').reset_index()pv['hr']=np.array(pv.TWD97_x)*15./3600.#in unit of hr/total hr