title: Count the number of duplicate grouped by ID pandas
body: <p>I'm not sure if this is a duplicate question, but here it goes.</p>
  <p>Assuming I have the following table:</p>
  <pre><code>import pandas
  
  lst = [1,1,1,2,2,3,3,4,5] 
  lst2 = ['A','A','B','D','E','A','A','A','E'] 
    
  df = pd.DataFrame(list(zip(lst, lst2)), 
                 columns =['ID', 'val'])
  </code></pre>
  <p>will output the following table</p>
  <pre><code>+----+-----+
  | ID | Val |
  +----+-----+
  | 1  | A   |
  +----+-----+
  | 1  | A   |
  +----+-----+
  | 1  | B   |
  +----+-----+
  | 2  | D   |
  +----+-----+
  | 2  | E   |
  +----+-----+
  | 3  | A   |
  +----+-----+
  | 3  | A   |
  +----+-----+
  | 4  | A   |
  +----+-----+
  | 5  | E   |
  +----+-----+
  </code></pre>
  <p>The goal is count the duplicates on VAL grouped by ID:</p>
  <pre><code>+----+-----+--------------+
  | ID | Val | is_duplicate |
  +----+-----+--------------+
  | 1  | A   | 1            |
  +----+-----+--------------+
  | 1  | A   | 1            |
  +----+-----+--------------+
  | 1  | B   | 0            |
  +----+-----+--------------+
  | 2  | D   | 0            |
  +----+-----+--------------+
  | 2  | E   | 0            |
  +----+-----+--------------+
  | 3  | A   | 1            |
  +----+-----+--------------+
  | 3  | A   | 1            |
  +----+-----+--------------+
  | 4  | A   | 0            |
  +----+-----+--------------+
  | 5  | E   | 0            |
  +----+-----+--------------+
  </code></pre>
  <p>I tried the following code but its counting the overall duplicates</p>
  <pre><code> df_grouped = df.groupby(['notes']).size().reset_index(name='count')
  </code></pre>
  <p>while the following code does only the duplicate count</p>
  <pre><code> df.duplicated(subset=['notes'])
  </code></pre>
  <p>what would be the best approach for this?</p>