title: How to use composition with pandas DataFrame and Series rather than inheritance
body: <p>I am very tempted to inheritance and subclass a pandas <code>DataFrame</code> for my use case, but from everything I've read about <a href="https://en.wikipedia.org/wiki/Composition_over_inheritance" rel="noreferrer">good programming</a> and the <a href="http://pandas.pydata.org/pandas-docs/stable/internals.html" rel="noreferrer">Pandas internals documentation</a> this is not the right thing to do.</p>
  
  <p>As a simplified example lets say the rows of my <code>DataFrame</code> are people and the fields are height and weight.  I'm tempted to subclass so that I can have a method which is <code>bmi()</code>.  I would do this as follows:</p>
  
  <p>import pandas as pd</p>
  
  <pre><code>class People(pd.DataFrame):
      def __init__(self, *args, **kwargs):
          super(People, self).__init__(*args, **kwargs)
  
      def bmi(self):
          return self['weight'] / self['height'] ** 2 x 703
  
  people = People([[172, 74], [100, 60]])
  bmi = people.bmi()
  </code></pre>
  
  <p>How would I do this using composition?  Would it be something like:</p>
  
  <pre><code>class People(object):
      def __init__(self, data):
          self.data = pd.DataFrame(data)
  
      def bmi(self):
          return self.data['weight'] / self.data['height'] ** 2 x 703
  
  people = People([[172, 74], [100, 60]])
  bmi = people.bmi()
  </code></pre>
  
  <p>If not, how would I do it?  If so, why is this better?</p>
  
  <p>Note: I realize this is an oversimplified example.</p>