I want to get a new GeoDataFrame in which each element is the union of N consecutive elements in my original GeoDataFrame.
I'd be very happy if this code worked, but it doesn't: the last step fails.
from shapely.geometry import Polygon
from shapely.ops import unary_union
import geopandas as gpd
p1 = Polygon([(1,1),(1,2),(2,2)])
p2 = Polygon([(1,1),(2,2),(2,1)])
p3 = Polygon([(1,1),(2,1),(2,0)])
gdf = gpd.GeoDataFrame(geometry=[p1, p2, p3])
gdf.rolling(window=2).apply(unary_union)
I would expect something that behaves like this
import pandas as pd
df = pd.DataFrame({'numbers': [1,2,3]})
df.rolling(window=2).apply(sum)
Out[1]:
numbers
0 NaN
1 3.0
2 5.0