title: Using Apply in Pandas Lambda functions with multiple if statements
body: <p>I'm trying to infer a classification according to the size of a person in a dataframe like this one:</p>
  
  <pre><code>      Size
  1     80000
  2     8000000
  3     8000000000
  ...
  </code></pre>
  
  <p>I want it to look like this:</p>
  
  <pre><code>      Size        Classification
  1     80000       &lt;1m
  2     8000000     1-10m
  3     8000000000  &gt;1bi
  ...
  </code></pre>
  
  <p>I understand that the ideal process would be to apply a lambda function like this:</p>
  
  <pre><code>df['Classification']=df['Size'].apply(lambda x: "&lt;1m" if x&lt;1000000 else "1-10m" if 1000000&lt;x&lt;10000000 else ...)
  </code></pre>
  
  <p>I checked a few posts regarding multiple ifs in a lambda function, <a href="https://stackoverflow.com/questions/33439434/multiple-if-statements-in-a-lambda-function">here is an example link</a>, but that synthax is not working for me for some reason in a multiple ifs statement, but it was working in a single if condition.</p>
  
  <p>So I tried this "very elegant" solution:</p>
  
  <pre><code>df['Classification']=df['Size'].apply(lambda x: "&lt;1m" if x&lt;1000000 else pass)
  df['Classification']=df['Size'].apply(lambda x: "1-10m" if 1000000 &lt; x &lt; 10000000 else pass)
  df['Classification']=df['Size'].apply(lambda x: "10-50m" if 10000000 &lt; x &lt; 50000000 else pass)
  df['Classification']=df['Size'].apply(lambda x: "50-100m" if 50000000 &lt; x &lt; 100000000 else pass)
  df['Classification']=df['Size'].apply(lambda x: "100-500m" if 100000000 &lt; x &lt; 500000000 else pass)
  df['Classification']=df['Size'].apply(lambda x: "500m-1bi" if 500000000 &lt; x &lt; 1000000000 else pass)
  df['Classification']=df['Size'].apply(lambda x: "&gt;1bi" if 1000000000 &lt; x else pass)
  </code></pre>
  
  <p>Works out that "pass" seems not to apply to lambda functions as well:</p>
  
  <pre><code>df['Classification']=df['Size'].apply(lambda x: "&lt;1m" if x&lt;1000000 else pass)
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>Any suggestions on the correct synthax for a multiple if statement inside a lambda function in an apply method in Pandas? Either multi-line or single line solutions work for me.</p>