title: Python Pandas : group by in groups by and average, count, median
body: <p>Suppose I have a dataframe that looks like this</p>
  <pre><code>d = {'User' : ['A', 'A', 'B', 'C', 'C', 'C'],
       'time':[1,2,3,4,4,4],
       'state':['CA', 'CA', 'ID', 'OR','OR','OR']}
  df = pd.DataFrame(data = d)
  </code></pre>
  <p>Now suppose I want to create new dataframe that takes the average and median of time, grabs the users state, and generate a new column as well that counts the number of times that user appears in the <code>User</code> column, i.e.</p>
  <pre><code>d = {'User' : ['A', 'B', 'C'],
       'avg_time':[1.5,3,4],
       'median_time':[1.5,3,4],
       'state':['CA','ID','OR'],
       'user_count':[2,1,3]}
  
  df_res = pd.DataFrame(data=d)
  </code></pre>
  <p>I know that I can do a group by mean statement like this</p>
  <pre><code>df.groupby(['User'], as_index=False).mean().groupby('User')['time'].mean()
  </code></pre>
  <p>This gives me a pandas series, and I assume I can make this into a dataframe if I wanted but how would I do the latter above for all the other columns I am interested in?</p>