Can I apply a vectorized function to a pandas dataframe?
<p>I am pretty new to <code>pandas</code> and <code>numpy</code>, and I'm trying to figure out the best way to do some things.</p>

<p>Right now I am trying to call a function on every row of a <code>dataframe</code>. If I pass in three <code>numpy</code> arrays to this function, it's very fast, but using <code>apply</code> on the <code>dataframe</code> is very slow.</p>

<p>My guess is that <code>numpy</code> is using vectorized functions in the first case, and not in the second. Is there a way to get <code>pandas</code> to use that optimization? Basically, in pseudocode I think <code>apply</code> is doing something like <code>for row in frame: func(row['a'], row['b'], row['c'])</code> but I want it to do <code>func(col['a'], col['b'], col['c'])</code>.</p>

<p>Here is an example of what I am trying to do.</p>

<pre><code>import numpy as np
import pandas as pd
from scipy.stats import beta

count = 100000

# If I start with a given dataframe and use apply, it's very slow

df = pd.DataFrame(np.random.uniform(0, 1, size=(count, 3)), columns=['a', 'b', 'c'])
df.apply(lambda frame: beta.cdf(frame['a'], frame['b'], frame['c']), axis=1)

# However, if I split out each column into a numpy array, this is very fast.

a = df['a'].as_matrix()
b = df['b'].as_matrix()
c = df['c'].as_matrix()

beta.cdf(a, b, c)

# But at this point I've lost the context of the dataframe.
# I would like to keep the results in a new column for further processing
</code></pre>