Python apply class method to row of data frame
<p>My class takes a row of a dataframe to construct an object and I would like to create an array of objects by applying init to every row of a dataframe. Is there a way to vectorize this? My class definition looks like</p>

<pre><code>class A(object):
    def __init__(self,row):
        self.a = row['a']
        self.b = row['b']
</code></pre>

<p>Any suggestion will be highly appreciated!</p>

<p>I have one way which I am not that satisfied with to solve this problem. Define another function outside of class and then use apply.  </p>

<pre><code>def InitA(row):
    return A(row)
</code></pre>

<p>Assume df is the data frame I want to use as argument.  </p>

<pre><code>xxx = df.apply(InitA,axis=1)
</code></pre>

<p>gives what I want. However, I don't think InitA is necessary.</p>

<p>My original problem is a bit more complicated. The class definition is</p>

<pre><code>class A(object):
    def __init__(self):
        return
    def add_parameter(self,row):
        self.a = row['a']
</code></pre>

<p>I intend to apply add_parameter to every row of a data frame. But I think defining another (lambda) function is necessary to solve this problem.</p>