I am working with two dataframes df1, df2 in Latitude/Longitude/Value format.
print(df1)
0 1 2
0 -85 -175 1.8
1 -80 -170 1.6
..
print(df2)
0 1 2
0 -70 -150 2.5
1 -80 -170 2.0
2 -85 -175 3.0
..
I'd like to multiply df1[2] by df2[2] if df1[0] = df2[0] and df1[1] = [1]. I tried using the following:
df1['multiplied']=np.where((df1[0]==df2[0],df1[2]*df2[2],np.nan) #if column 1 of df1 equals column 1
#of df2, multiply. Else give NaN
I am aware that I neglect the second condition in this example. Downside here is, comparison of column values is element-wise (my lat/lon data are not sorted). Also different df size causes an error "Can only compare identically-labeled Series objects".
In another approach, I tried checking whether df1[0] and df2[0] are the same and give out a new df that matches the criteria:
dfnew=df1.loc[df1[0]==df2[0]]
This lead me to the same error as above.
I wonder if you have any advice on how to apply conditional calculations on unsorted dataframes of different size?