I want to update the values in a GeoPanda dataframe from another GeoPanda dataframe for select columns. Both of them will have a common key called 'geometry.'
For example
df1 = pd.DataFrame([["X",1,1,0],
["Y",0,1,0],
["Z",0,0,0],
["Y",0,0,0]],columns=["geometry","Nonprofit","Business", "Education"])
df2 = pd.DataFrame([["Y",1,1],
["Z",1,1]],columns=["geometry","Non", "Edu"])
Following this answer I did the following steps:
df1 = df1.set_index('geometry')
df2 = df2.set_index('geometry')
list_1 = ['Nonprofit', 'Education']
list_2 = ['Non', 'Edu']
df1[list_1].update(df2[list_2])
This results in the wrong results without any warning. How can I fix this?
Notes:
Updating one column at a time (df1['Nonprofit'].update(df2['Non'])) will produce the correct result.
geometry Linestring from GeoPandas replaced by a character for simplicity.