擅长:python、mysql、java
<p>您可以将两个数据帧转换为长格式,然后根据日期合并并选择*,然后将结果转换回宽格式:</p>
<pre><code>(df1.stack().to_frame("Product") # reshape df1 to long format
.join(df2.stack().rename("Value")) # reshape df2 to long format and join with df1
.reset_index(level = 1, drop = True) # drop the original column names
.pivot(columns="Product", values="Value")) # reshape to wide format
</code></pre>
<p><a href="https://i.stack.imgur.com/UKzz4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UKzz4.png" alt="enter image description here"/></a></p>