merging dataframes depending on values

Viewed 25

I have two dataframes with different sizes and I'd like to merge them.

df's with different sizes

Now I'd like to merge them, that the height values of the first columns are corresponding. 15.0 with 15.0 and so on. The missing values should be filled with NaNs or interpolated.

Is there a nice way of doing that without checking every value in a for loop?

Would appreciate any suggestions.

Thanks J.

1 Answers

You could try using a left join with pd.merge() so that you keep everything on the 1st dataframe

Example:

#left_df will represent your first dataframe
#right_df will represent your second dataframe

pd.merge(left_df, right_df, left_on = "height", right_on = "height_radio", how = "left")
Related