'Replacing ID values of polygons in a geodataframe to values of polygons from another geodataframe

I have polygons inside another bigger single polygon and I want to be able to replace the ID values (for example) of the former polygon to that of the latter.

Suppose I have a geodataframe with 3 polygons and the IDs of them are [8, 20, 55]. Now, these polygons are actually inside another bigger polygon (second geodataframe) with an ID of [2]. I want to know how it is possible to convert the values of [8,20,55] from the first geodataframe to [2,2,2] according to the bigger polygon from the second geodataframe. Conceptually the image looks like this:

this



Solution 1:[1]

Use sjoin:

gdf1['ID'] = gdf1.sjoin(gdf2, how='left', predicate='within')['ID_right']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien