title: finding class-wise accuracy in pandas using value_counts()
body: <p>I have two columns in a pandas dataframe : label(ground truth) and pred (model prediction). I have 4 classes in the labels: dog, cat, elephant and snake. What I want is the accuracy or precision of the prediction per class. For instance if I have dataframe below:</p>
  
  <pre><code>label    pred
  dog      cat
  elephant elephant
  dog    snake
  cat     cat
  snake   snake
  snake   cat
  dog    dog
  </code></pre>
  
  <p>What I do is use value_counts for each class and then manually plug in the ratios to get the accuracy in pandas. The problem is that value_counts is sorted by raw count numbers so the order for label and pred can be different.</p>
  
  <pre><code>numerators = df[pred].value_counts()
     denominators = df[label].value_counts()
  </code></pre>
  
  <p>and then I get the outputs:</p>
  
  <pre><code> dog    0.33
    cat   1
    snake  0.5
    elephant 1 
  </code></pre>
  
  <p>Is there a way to automate this in pandas? </p>