title: Pandas: calculate the std of total column value per "year"
body: <p>I have a data frame representing the customers checkins (visits) of restaurants. <code>year</code> is simply the year when a checkin in a restaurant happened .</p>
  <ul>
  <li><strong>What i want to do is to add a column <code>std_checkin</code> to my initial Dataframe <code>df</code> that represents the standard deviation of visits per year. So, I need to calculate the standard deviation for the total visits per year.</strong></li>
  </ul>
  <pre class="lang-py prettyprint-override"><code>data = {
          'restaurant_id':  ['--1UhMGODdWsrMastO9DZw', '--1UhMGODdWsrMastO9DZw','--1UhMGODdWsrMastO9DZw','--1UhMGODdWsrMastO9DZw','--1UhMGODdWsrMastO9DZw','--1UhMGODdWsrMastO9DZw','--6MefnULPED_I942VcFNA','--6MefnULPED_I942VcFNA','--6MefnULPED_I942VcFNA','--6MefnULPED_I942VcFNA'],
          'year': ['2016','2016','2016','2016','2017','2017','2011','2011','2012','2012'],
          }
  df = pd.DataFrame (data, columns = ['restaurant_id','year'])
  
  # total number of checkins per restaurant
  d = df.groupby('restaurant_id')['year'].count().to_dict()
  df['nb_checkin'] = df['restaurant_id'].map(d)
  
  
  grouped = df.groupby([&quot;restaurant_id&quot;])
  avg_annual_visits = grouped[&quot;year&quot;].count() / grouped[&quot;year&quot;].nunique()
  avg_annual_visits = avg_annual_visits.rename(&quot;avg_annual_visits&quot;)
  df = df.merge(avg_annual_visits, left_on=&quot;restaurant_id&quot;, right_index=True)
  
  df.head(10)
  </code></pre>
  <p>From here, I'm not sure how to write what i want with pandas. If any clarifications needed, please ask.</p>
  <p>Thank you!</p>