title: Creating class object from pandas series and applying methods
body: <p>I have a function that reads in a bunch of raw data with some user-input and compiles it into a Pandas series. In the example below I call it <code>create_data</code> and it just builds a random Series of length <code>n</code>. </p>
  
  <pre><code>&gt;&gt;&gt; def create_data(n):
  ...     return pd.Series(np.random.randint(1, 100, n))
  ... 
  &gt;&gt;&gt; 
  &gt;&gt;&gt; function_result=create_data(10)
  &gt;&gt;&gt; function_result
  0    73
  1    91
  2    31
  3    44
  4    19
  5    30
  6    42
  7    56
  8    69
  9    70
  dtype: int32
  </code></pre>
  
  <p>Then I have a set of functions that want to be able to apply to this series. In this example, I create one that calculates the correlation between the series and its first-degree difference.</p>
  
  <pre><code>&gt;&gt;&gt; def temporal_corr(x):
  ...     return pd.concat([x, x.shift()], 1).corr().iloc[0, 1]
  ... 
  </code></pre>
  
  <p>I can obviously just apply it to series by calling the function...</p>
  
  <pre><code>&gt;&gt;&gt; temporal_corr(function_result)
  0.38714413906049816
  </code></pre>
  
  <p>But let's say I have several different functions that I want to use on this series. Would it make more sense (or is it possible), to create a class that constructs an object using the function <code>create_data</code> and then have a set of functions within the class that can be applied as methods? I create a class and define this function below.</p>
  
  <pre><code>&gt;&gt;&gt; class myobj:
  ...     def __init__(self, myobj):
  ...         self.myobj = myobj
  ...     
  ...     def temporal_corr(self):
  ...         return pd.concat([self.myobj, self.myobj.shift()], 1).corr().iloc[0, 1]
  ... 
  &gt;&gt;&gt; a = myobj(function_result)
  &gt;&gt;&gt; a.temporal_corr()
  0.38714413906049816
  </code></pre>
  
  <p>What is the best way to have the class object <code>myobj</code> be created as a result of the function <code>create_data</code>? I would like to be able to call <code>create_data</code> and have the result be an object from which I can call <code>temporal_corr()</code>. </p>