title: How to extend Pandas Dataframe to create custom class where it is initialized with a csv filename?
body: <p>I want to create a special type of object, based on the <code>pandas.DataFrame</code> object, which will always be created based on a particular input file type.</p>
  
  <p>I have been able to design a class that can be created the same way as a normal DataFrame, i.e.:</p>
  
  <pre><code>class CustomDF(pd.DataFrame):
      ...
  
  Obj = CustomDF({'a':[1,2],'b':[3,4]})
  </code></pre>
  
  <p>But I want to change the initialization behaviour to accept a csv filename and import it. I know Pandas allows this using:</p>
  
  <pre><code>df = pd.read_csv(filename)
  </code></pre>
  
  <p>But I can't get it to work within my new class when I do:</p>
  
  <pre><code>class CustomDF(pd.DataFrame):
      def  __init__(self, filename):
          self = pd.read_csv(filename)
  </code></pre>
  
  <p>And although there is no error when I create an object with this class, I do get the error <code>'CustomDF' object has no attribute '_data'</code> when trying to access it.</p>
  
  <p>I have tried changing <code>self = pd.read_csv(filename)</code> to <code>self._data = pd.read_csv(filename)</code> or <code>self.data = pd.read_csv(filename)</code> but this doesn't have any effect.</p>
  
  <p>What is the proper way to accomplish this? Is there a better approach to doing this same thing?</p>