title: How can I create a new column containing 0 and 1 values via groupby("col1")?
body: <p>I have a dataframe like this:</p>
  <pre><code>df = pd.DataFrame({&quot;col1&quot;:[&quot;a&quot;,&quot;a&quot;,&quot;a&quot;,&quot;b&quot;,&quot;b&quot;,&quot;c&quot;,&quot;c&quot;,&quot;c&quot;,&quot;c&quot;,&quot;d&quot;]})
  </code></pre>
  <p>How can I create a new column containing 0 and 1 values via groupby(&quot;col1&quot;) ?</p>
  <pre><code>  col1 col2
  0   a   0
  1   a   0
  2   a   0
  3   b   1
  4   b   1
  5   c   0
  6   c   0
  7   c   0
  8   c   0
  9   d   1
  </code></pre>