how do you map a pandas dataframe column to a function which requires more than one parameter
<p>I have a function which has two arguments, the first argument is some text the second a regex pattern. </p>

<p>I want to pass each row of a certain column from my dataframe to a function using .map however I am not sure how to direct the data from the dataframe to be the first argument and the regex (which will be the same pattern for each row) to be the second argument?</p>

<pre><code>def regex(pattern,text):
    p = pattern
    t = str(text)
    results = re.findall(p,t)
    return results

df['new_column'] = df['source_code'].map(some_function)
</code></pre>

<p>I think you need <code>lambda</code> function with parameters <code>pattern</code> and <code>x</code>:</p>

<pre><code>df['new_column'] = df['source_code'].map(lambda x: some_function(pattern, x))

df['new_column'] = df['source_code'].apply(lambda x: some_function(pattern, x))
</code></pre>

<p>Thank you <a href="http://stackoverflow.com/questions/40018755/how-do-you-map-a-pandas-dataframe-column-to-a-function-which-requires-more-than#comment67315401_40019301">Jon Clements</a> for another solution:</p>

<pre><code>df['new_column'] = df['source_code'].apply(some_function, args=(pattern ,x)) 
</code></pre>

python regex pandas