I have a large dataframe with coordinate values (lat/long) and a measurement value associated with each coordinate. If I plot the values directly, the points overlap. This is why I would like to create a grid or raster and calculate a mean of all point values within each raster cell, so that I can create a nice plot.
In R I can do this using the raster library, but I would like something comparable in Python:
library(raster)
# create random sample data set
x <- round(rnorm(100, 0, 50),4)
y <- round(rnorm(100, 0, 50),4)
z <- round(rnorm(100, 2), 4)
# set raster dimensions
r <- raster(ncols = 20, nrows = 20)
xy <- cbind(x, y)
vals <- z
# calculate mean of the values associated with the points in each raster cell
r3 <- rasterize(xy, r, vals, fun = mean)
plot(r3, main="rasterized plot")
Plot:
https://i.stack.imgur.com/yqimI.png
I cannot find anything like this for Python. Is there a comparable method?
Thank you!