title: Pandas to mark rows fit conditions
body: <p><a href="https://i.stack.imgur.com/WDlTf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WDlTf.png" alt="enter image description here" /></a></p>
  <p>A simple dataset and I want to mark the rows with below conditions, if:</p>
  <p>both the columns Close and End are older than today</p>
  <p>and, column Stage in [One, Two, Three]</p>
  <p>and, column Project Number is not blank</p>
  <p>I came up with below lines, but it doesn't work.</p>
  <pre><code>import pandas as pd
  import datetime
  import numpy as np
  from io import StringIO
  
  
  csvfile = StringIO(&quot;&quot;&quot;
  ID  Stage   Close   Project Number  End&quot;
  A899    One 26/08/2019  KL1468  30/08/2019&quot;
  A572    Two 31/12/2020  KL1493  17/12/2019&quot;
  A778    Three   26/08/2019      16/08/2019&quot;
  A704    Four    31/12/2020  KL1036  01/12/2019&quot;
  A650    One 31/12/2020  KL1522  23/12/2019&quot;
  A830    Two 31/08/2021  KL1535  03/08/2021&quot;
  A669    Three   18/08/2021  KL1536  03/08/2021&quot;
  A892    Four    31/08/2021  KL1534  03/08/2021&quot;
  A789    One 31/05/2021  KL1537  04/08/2021&quot;
  A821    Two 31/12/2020  KL1578  03/11/2019&quot;
  A992    Three   29/07/2019  KL1609  26/06/2019&quot;
  A550    Four    31/12/2020  KL1243  30/11/2019&quot;
  A707    One 31/12/2020  KL1523  29/11/2019&quot;
  A740                
  A917    Three   31/07/2021  KL1072  29/07/2021&quot;
  A627    Four    30/06/2021  KL1577  15/06/2021&quot;
  
  &quot;&quot;&quot;)
  
  df = pd.read_csv(csvfile, sep = '\t', engine='python')
  
  def condition_1(s):
      if (df['Project Number'].any() and s['Expiry_1'] &lt; datetime.datetime.now() and s['Close_1'] &lt; datetime.datetime.now() and np.where(df['Stage'].isin(['One','Two','Three']))):
          return &quot;Overdue&quot;
      else:
          return ''
  
  df['Expiry_1'] = pd.to_datetime(df['End'].str[3:5] + '/' + df['End'].str[:2] + '/' + df['End'].str[-4:])
  df['Close_1'] = pd.to_datetime(df['Close'].str[3:5] + '/' + df['Close'].str[:2] + '/' + df['Close'].str[-4:])
  df[&quot;Overdue Project&quot;] = df.apply(condition_1, axis=1)
  
  df.to_excel(&quot;c:\\Projects\\output.xlsx&quot;, index = False)
  </code></pre>
  <p>What went wrong, and what's the right way to achieve it? Thank you.</p>