基于多索引中的一个层次和另一层次的索引的数据帧乘法

时间:2018-07-19 16:11:33

标签: python indexing matrix-multiplication

我有两个数据框:

df1 (1-level index dataframe):

stock                         stock1  stock2 ...   \
timestamp                                                                     
2012-10-19 11:00:00           1.44    NaN    NaN    NaN    NaN    NaN  8.040162   
2012-10-19 11:05:00           1.45    NaN    NaN    NaN    NaN    NaN  8.052665   
2012-10-19 11:10:00           1.45    NaN    NaN    NaN    NaN    NaN  8.040162   
2012-10-19 11:15:00           1.44    NaN    NaN    NaN    NaN    NaN  8.040162 


df2(2-level index dataframe):

stock                        stock1  stock2  ...\
id    timestamp                                                             
10000 2012-10-19 09:05:00     0      0      0      0      0      0       0   
      2012-10-19 09:10:00     0      0      0      0      0      0       0   
      2012-10-19 09:15:00     0      0      0      0      0      0     963   
      2009-10-19 09:20:00     0      0      0      0      0      0     592   
      2009-10-19 09:25:00     0      0      0      0      0      0       0  

如何将df1中的值与df2中的相应值相乘(基于相同的时间戳记),并创建一个具有相乘的值和df2中的索引的新矩阵?我的问题是df1在df2中不是唯一的,它们的索引是不同的,我想保留df2的索引。

0 个答案:

没有答案