title: Use custom function (Median Absolute Deviation) in Pandas `transform()`
body: <p>I have a pandas dataframe for which I want to compute the MEDIAN Absolute Deviation by cluster. I assumed that the pandas method <code>mad</code> was the Median Absolute Deviation, but it appears that it is the MEAN Absolute Deviation. The line of code i have written is</p>
  
  <pre><code>df['MAD PPGamp'] = df.groupby('Cluster')['PPGamp'].transform('mad')
  </code></pre>
  
  <p>I tried to write a little function of my own to compute the Median Absolute Deviation</p>
  
  <pre><code>def myMAD(x):
      med = np.median(x)
      x   = abs(x-med)
      MAD = np.median(x)
      return MAD
  </code></pre>
  
  <p>and to change my code to read</p>
  
  <pre><code>df['MAD PPGamp'] = df.groupby('Cluster')['PPGamp'].transform('myMAD')
  </code></pre>
  
  <p>Unfortunately this does doesn't work. I get an AttributeError 'SeriesGroupBy' object has no attribute 'myMAD".</p>
  
  <p>How can I compute the Median Absolute deviations by cluster for  a column in my dataframe and create a new column with the MAD broadcast across rows correctly using transform?</p>
  
  <p>Thanks in advance</p>
  
  <p>Thomas Philips</p>