Gridding/binning data

148 views Asked by At

I have a dataset with three columns: lat, lon, and wind speed. My goal is to have a 2-dimensional lat/lon gridded array that sums the wind speed observations that fall within each gridbox. It seems like that should be possible with groupby or cut in pandas. But I can't puzzle through how to do that.

Here is an example of what I'm trying to replicate from another language: https://www.ncl.ucar.edu/Document/Functions/Built-in/bin_sum.shtml

1

There are 1 answers

1
Charles On

It sounds like you are using pandas. Are the data already binned? If so, something like this should work

data.groupby(["lat_bins", "lon_bins"]).sum()

If the lat and lon data are not binned yet, you can use pandas.cut to create a binned value column like this

data["lat_bins"] = pandas.cut(x = data["lat"], bins=[...some binning...])