title: Python: Lambda if else statement when Pandas Dataframe is empty
body: <p>I have a dataframe like so:</p>
  <pre><code>            df
  Id    Severity    First Discovered
  0      Low            1/1/2021
  1      Medium         1/1/2021
  2      Medium         1/1/2021
  </code></pre>
  <p>I've also defined a function below that assists in creating &quot;Target Close Date&quot; which adds a certain number of days to the &quot;First Discovered&quot; field depending on what the corresponding &quot;Severity&quot; value is.</p>
  <pre><code>def get_target_close_date(severity, first_discovered_date):
      '''Adds days to first discovered date depending on severity'''
      if severity == 'Low':
          target_close_date = first_discovered_date + timedelta(days=30)
      elif severity == 'Medium':
          target_close_date = first_discovered_date + timedelta(days=60)
  
      return target_close_date
  </code></pre>
  <p>By executing <code>df['Target Close Date'] = df.apply(lambda row: get_target_close_date(row['Severity'], row['First Discovered']), axis=1)</code>, the dataframe updates correctly:</p>
  <pre><code>         df
  Id    Severity    First Discovered    Target Close Date
  0      Low            1/1/2021             1/31/2021
  1      Medium         1/1/2021             3/2/2021
  2      Medium         1/1/2021             3/2/2021
  </code></pre>
  <p>However, if the dataframe is empty, the code does not work, and I get a <strong>ValueError: Wrong number of items passed 3, placement implies 1</strong>. I ideally want to add an if else statement to the lambda function to check if dataframe is empty, something like:</p>
  <pre><code>df['Target Close Date'] = df.apply(
    lambda row: get_target_close_date(row['Severity'], row['First Discovered']) if not df.empty else pass, 
      axis=1)
  </code></pre>
  <p>This keeps returning a syntax error however. I would prefer to write the if else conditional inside the lambda function rather than doing an if else statement that spans across multiple lines.</p>