title: Numpy broadcasting and for loop
body: <p>I have two pd.dataframes.</p>
  
  <pre><code>       df1
  
             Equipment_Class    0     1       2         3
                 PC1         8.72     7.32    0.17    0.00
                 PC2        19.18     10.11   8.72    0.35
  
  
         df2
              Year    Equipment_Class     0         1          2        3
              2024    PC1                0.7       0.3      0.1         0.0
              2025    PC1                0.6       0.3      0.1         0.0
              2026    PC1                0.6       0.3      0.1         0.0
              2027    PC2                0.4       0.5      0.1         0.0         
              2028    PC2                0.2       0.5      0.1         0.2
              2029    PC2                0.3       0.5      0.1         0.1
  </code></pre>
  
  <p>I want to multiply df1.loc[0, "0":"3"] and df2.loc[0:, "0":"3"] if Equipment_Class are match in both dfs, i.e., Equipment_class == "PC1" or "PC2"</p>
  
  <p>I also want to do a for loop, so I don't have to manually add on columns.</p>
  
  <p>Below is my code so far:</p>
  
  <pre><code>  df3=pd.DataFrame(columns=['PC1','PC2'])
    col_names=df1.Equipment_Class
  
    for incol,df3column in zip(col_names, df3.columns):
        df3[df3column]=df1.loc[df1.Equipment_Class==incol, "0":"3"].to_numpy() 
                     [None,:]*df2.loc[df2.Equipment_Class==incol, "0":"3"]
  </code></pre>
  
  <p>I got following error message:
        ValueError: Unable to coerce to Series/DataFrame, dim must be &lt;= 2: (1, 1, 4)</p>
  
  <p>Thank you for your help. </p>