title: calculate pandas column on subset of data
body: <p><strong>Background</strong></p>
  <p>I have a dataframe with 3 columns and 40,000 rows.</p>
  <pre><code>index     Time                             wind speed   sector
  0         2019-12-01 10:00:00+10:00        4.970969     120
  1         2019-12-01 11:00:00+10:00        5.076307     30
  2         2019-12-01 12:00:00+10:00        5.248692     90
  3         2019-12-01 13:00:00+10:00        5.242391     60
  4         2019-12-01 14:00:00+10:00        5.266173     30
  ...
  </code></pre>
  <p><strong>What I'm trying to do</strong></p>
  <p>I need to create a new column with standard deviation of wind speed by sector.
  i.e. for all 40,000 rows, group all the wind speed numbers which have the same sector, and calculate their standard deviation</p>
  <p><strong>What I've tried</strong></p>
  <p>I've looked across stack and I know I need to use 'groupby', but in all the other posts, people where not adding this column to the existing df.</p>
  <p>I've tried the following but with no success</p>
  <pre><code>df['std'] = df.groupby(['sector'])['wind speed'].std()
  df['std'] = df['wind speed'].apply(lambda x: df.groupby('sector')[x].std())
  </code></pre>
  <p><strong>Help Requested</strong></p>
  <p>does anyone know how I need to write the groupby function to work?</p>