Pandas - Group/bins of data per longitude/latitude

前端 未结 1 1124
轮回少年
轮回少年 2021-01-02 06:57

I have a bunch of geographical data as below. I would like to group the data by bins of .2 degrees in longitude AND .2 degree in latitude.

While it is trivial to do

相关标签:
1条回答
  • 2021-01-02 07:37

    How about this?

    step = 0.2
    to_bin = lambda x: np.floor(x / step) * step
    df["latbin"] = df.Latitude.map(to_bin)
    df["lonbin"] = df.Longitude.map(to_bin)
    groups = df.groupby(("latbin", "lonbin"))
    
    0 讨论(0)
提交回复
热议问题