title: Implementing own function in pandas data frame
body: <p>I am implementing my own function for calculating taxes. Below you can see the data</p>
  <pre><code>df = pd.DataFrame({&quot;id_n&quot;:[&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;],
                                 &quot;sales1&quot;:[0,115000,440000,500000,740000],
                                 &quot;sales2&quot;:[0,115000,460000,520000,760000],
                                 &quot;tax&quot;:[0,8050,57500,69500,69500]
                    })
  </code></pre>
  <p><a href="https://i.stack.imgur.com/sbKap.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sbKap.png" alt="enter image description here" /></a></p>
  <p>Now I want to introduce a tax function that needs to give the same results as results in column tax. Below you can see an estimation of that function:</p>
  <pre><code>            # Thresholds
          min_threeshold = 500000
          max_threeshold = 1020000
              
              # Maximum taxes
          max_cap = 69500
              
              # Rates
          rate_1 = 0.035
          rate_2 = 0.1 
              
              # Total sales
          total_sale = df['sales1'] + df['sales2']
          tax = df['tax']
      
      # Function for estimation
      def tax_fun(total_sale,tax,min_threeshold,max_threeshold,max_cap,rate_1,rate_2):
          if (total_sale &gt; 0 and tax == 0):
             calc_tax = 0
          elif (total_sale &lt; min_threeshold): 
             calc_tax = total_sale * rate_1  
          elif (total_sale &gt;= min_threeshold) &amp;  (total_sale &lt;= max_threeshold): 
             calc_tax =  total_sale * rate_2 
          elif (total_sale &gt; max_threeshold):
            calc_tax = max_cap  
          return calc_tax
  </code></pre>
  <p>So far so good. The next step is the execution of the above function. Below you can see the command :</p>
  <pre><code>df['new_tax']=tax_fun(total_sale,tax,min_threeshold,max_threeshold,max_cap,rate_1,rate_2)
  </code></pre>
  <p>After execution of this command, I received this error</p>
  <pre><code>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
  </code></pre>
  <p>So can anybody help me how to solve this problem?</p>