title: Why use to_frame before reset_index?
body: <p>Using a data set like this one </p>
  
  <pre><code>df = pd.DataFrame(np.random.randint(0,5,size=(20, 3)), columns=['user_id','module_id','week'])
  </code></pre>
  
  <p>we often see this pattern:</p>
  
  <pre class="lang-python prettyprint-override"><code>df.groupby(['user_id'])['module_id'].count().to_frame().reset_index().rename({'module_id':'count'}, axis='columns')
  </code></pre>
  
  <p>But we get exactly the same result from </p>
  
  <pre class="lang-python prettyprint-override"><code>df.groupby(['user_id'])['module_id'].count().reset_index(name='count')
  </code></pre>
  
  <p>(N.B. we need the additional <code>rename</code> in the former because <code>reset_index</code> on Series (<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.reset_index.html" rel="nofollow noreferrer">here</a>) includes a <code>name</code> parameter and returns a data frame, while <code>reset_index</code> on DataFrame (<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.reset_index.html" rel="nofollow noreferrer">here</a>) does not include the <code>name</code> parameter.)</p>
  
  <p>Is there any advantage in using <code>to_frame</code> first?</p>
  
  <p>(I wondered if it might be an artefact of earlier versions of pandas, but that looks unlikely:</p>
  
  <ul>
  <li><code>Series.reset_index</code> was added in <a href="https://github.com/pandas-dev/pandas/commit/12094e9a6bfe0e941289eb2b20863a792ba38b58" rel="nofollow noreferrer">this commit</a> on the 27th of January 2012.</li>
  <li><code>Series.to_frame</code> was added in <a href="https://github.com/pandas-dev/pandas/commit/844bcff0917af28907483be3cd927a07edb8f53d" rel="nofollow noreferrer">this commit</a> on the 13th of October 2013.</li>
  </ul>
  
  <p>So <code>Series.reset_index</code> was available over a year before <code>Series.to_frame</code>.)</p>