title: Equivalent of transform in R/ddply in Python/pandas?
body: <p>In R's ddply function, you can compute any new columns group-wise, and append the result to the original dataframe, such as:</p>
  
  <pre><code>ddply(mtcars, .(cyl), transform, n=length(cyl)) # n is appended to the df
  </code></pre>
  
  <p>In Python/pandas, I have computed it first, and then merge, such as:</p>
  
  <pre><code>df1 = mtcars.groupby("cyl").apply(lambda x: Series(x["cyl"].count(), index=["n"])).reset_index()
  mtcars = pd.merge(mtcars, df1, on=["cyl"])
  </code></pre>
  
  <p>or something like that.</p>
  
  <p>However, I always feel like that's pretty daunting, so is it feasible to do it all once?</p>
  
  <p>Thanks.</p>