title: Eigenvalues from pandas rows
body: <p>I have a <code>pandas</code> <code>DataFrame</code> with rows representing a symmetric matrix component. </p>
  
  <pre><code>                            sxx         syy             szz         sxy         syz         sxz                                                                                           
      NodeID      time
      1500000     20921.0     2504729.0   -16524560.0     -3966213.0  5058878.0   8026349.0   390275.7
                  20923.0     2541577.0   -16459500.0     -3930280.0  5047995.0   8019404.0   393201.3
                  20925.0     2582004.0   -16384690.0     -3891037.0  5035703.0   8011226.0   396850.2
                  20927.0     2618859.0   -16313310.0     -3855520.0  5024095.0   8003384.0   400578.7
                  20933.0     2703961.0   -16133460.0     -3773937.0  4995101.0   7985394.0   411183.2
  </code></pre>
  
  <p>The matrix will look like the following.</p>
  
  <pre><code>[[sxx, sxy, sxz],
   [sxy, syy, syz],
   [sxz, syz, szz]]
  </code></pre>
  
  <p>What is the fastest way to calculate the eigenvalue from each row?</p>
  
  <p>I tried 'applying' <code>np.linalg.eigvalsh</code> on every row. However, it takes quite long when I have close to a million lines.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>To give the complete context, I should also mention that this <code>DataFrame</code> is part of an object definition. <code>object.df</code> is the <code>DataFrame</code>. Below is the related code.</p>
  
  <pre class="lang-py prettyprint-override"><code>    def s1(self):
          """Returns the first principal stress for every node every timepoint"""
          return self.df.apply(principal, axis=1, label="s1")
  
  def principal(s, label):
      principals = np.linalg.eigvalsh(
          np.array(
              [s.sxx, s.sxy, s.sxz, s.sxy, s.syy, s.syz, s.sxz, s.syz, s.szz]
          ).reshape(3, 3)
      )
      if label.lower() == "s3":
          return principals[0]
      elif label.lower() == "s2":
          return principals[1]
      elif label.lower() == "s1":
          return principals[2]
      else:
          raise ValueError("Invalid Input, choose from s1, s2, or s3.")
  </code></pre>