0

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 Answers1

0

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...])
Charles
  • 97
  • 5
  • The data were not yet binned. So the issue was that I needed to use cut, but cut only works on one column at a time. But stats.binned_statistic_2d did the trick. Thanks! – weatherwolfcarl May 25 '20 at 16:19