title: Passing multiple arguments to apply (Python)
body: <p>I'm trying to clean up some code in Python to vectorize a set of features and I'm wondering if there's a good way to use apply to pass multiple arguments. Consider the following (current version):</p>
  
  <pre><code>def function_1(x):
      if "string" in x:
          return 1
      else:
          return 0
  
  df['newFeature'] = df['oldFeature'].apply(function_1)
  </code></pre>
  
  <p>With the above I'm having to write a new function (function_1, function_2, etc) to test for each substring <code>"string"</code> that I want to find. In an ideal world I could combine all of these redundant functions and use something like this:</p>
  
  <pre><code>def function(x, string):
      if string in x:
          return 1
      else:
          return 0
  
  df['newFeature'] = df['existingFeature'].apply(function("string"))
  </code></pre>
  
  <p>But trying that returns the error <code>TypeError: function() takes exactly 2 arguments (1 given)</code> Is there another way to accomplish the same thing?</p>
  
  <h2><strong>Edit:</strong></h2>
  
  <pre><code>def function(string, x):
      if string in x:
          return 1
      else:
          return 0
  
  df['newFeature'] = df['oldFeature'].apply(partial(function, 'string'))
  </code></pre>