title: Pandas custom accessor with instance variable
body: <p>I'm trying to <a href="https://pandas.pydata.org/pandas-docs/stable/development/extending.html" rel="nofollow noreferrer">extend</a> <code>pd.DataFrame</code> with some extra functionality. I have the methods working fine, but I want to store some additional data as an instance variable, and I'm having unexpected trouble.</p>
  
  <p>So far, I have:</p>
  
  <pre><code>@pd.api.extensions.register_dataframe_accessor('foo')
  class Foo:
  
      def __init__(self, df):
          self._df = df
  
      @staticmethod
      def load_data(arg):
          data = doStuff(arg)
          obj = pd.DataFrame(data)
          # Remember how this object was made
          obj.__dict__['arg'] = arg
          return obj        
  </code></pre>
  
  <p>(The awkward assignment to <code>obj.__dict__</code>, instead of just saying <code>obj.arg = arg</code>, prevents Pandas from treating this as an attempt to make a column. I learned to do this when I once subclassed DataFrame, which was quite a headache.)</p>
  
  <p>Then I do:</p>
  
  <pre><code>obj = Foo.load_data('stuff')
  obj.arg
  obj.foo.arg
  obj.foo._df.arg
  </code></pre>
  
  <p>Each of the last 3 lines leads to an <code>AttributeError</code>. I know I assigned the property... where did it go?</p>