简体   繁体   English

根据值合并数据框

[英]merging dataframes depending on values

I have two dataframes with different sizes and I'd like to merge them.我有两个不同大小的数据框,我想合并它们。

不同尺寸的 df

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. 15.0 与 15.0 等等。 The missing values should be filled with NaNs or interpolated.缺失值应该用 NaN 填充或进行插值。

Is there a nice way of doing that without checking every value in a for loop?有没有一种不检查 for 循环中的每个值的好方法?

Would appreciate any suggestions.将不胜感激任何建议。

Thanks J.谢谢 J。

You could try using a left join with pd.merge() so that you keep everything on the 1st dataframe您可以尝试将左连接与 pd.merge() 结合使用,以便将所有内容都保留在 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM