title: Getting weighted average and standard deviation on several columns in Pandas
body: <p>I am trying to do weighted standard deviation on top of weighted average on my <code>pandas</code> dataframe. I have a <code>pandas</code> dataframe like:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  df = pd.DataFrame({"Date": pd.date_range(start='2018-01-01', end='2018-01-03 18:00:00', freq='6H'),
                 "Weight": np.random.uniform(3, 5, 12),
                 "V1": np.random.uniform(10, 15, 12),
                 "V2": np.random.uniform(10, 15, 12),
                 "V3": np.random.uniform(10, 15, 12)})
  </code></pre>
  
  <p>Currently, to get the weighted mean, inspired by <a href="https://stackoverflow.com/a/35327787/3799296">this post</a>, I am doing the following:</p>
  
  <pre><code>def weighted_average_std(grp):
      return grp._get_numeric_data().multiply(grp['Weight'], axis=0).sum()/grp['Weight'].sum()
  df.index = df["Date"]
  df_agg = df.groupby(pd.Grouper(freq='1D')).apply(weighted_average_std).reset_index()
  df_agg
  </code></pre>
  
  <p>Where I get the following:</p>
  
  <pre><code>    Date    V1  V2  V3  Weight
  0   2018-01-01  11.421749   13.090178   11.639424   3.630196
  1   2018-01-02  12.142917   11.605284   12.187473   4.056303
  2   2018-01-03  12.034015   13.159132   11.658969   4.318753
  </code></pre>
  
  <p>I want to modify <code>weighted_average_std</code> so that it returns standard deviation for each column in addition to <code>weighted average</code>. The idea is to use the weighted average for each group in a vectorized fashion. The new column names for <code>Weighted Standard Deviation</code> can be something like <code>V1_WSD</code>, <code>V2_WSD</code> and <code>V3_WSD</code>. </p>
  
  <p>PS1: <a href="https://stats.stackexchange.com/a/61298/55348">This post</a> goes through the theory of weighted standard deviation. </p>
  
  <p>PS2: Column <code>Weight</code> in <code>df_agg</code> is meaningless. </p>