title: Execute script inside conditional statement Using Python
body: <p>I have been Trying to execute the rest of the cleaning script if satisfies an specific condition. Actually have a input Excel dataset where data keeps on adding after an equal interval. I am only looking to process the rest of the script if column flag= &quot;Not feasible&quot;, Else will going to keep the data as it is .</p>
  <p>In the end I want to display all the data at the time (One processed through script) + (Not Processed through Script)</p>
  <p><strong>Input Data :</strong></p>
  <pre><code>name   age   Contact    col4   col5  col6  flag
  
  NKJ    48!   96754789   8886H  AHBZ        Not feasible
  Tom    27    98468300   ^686H  ANKZ        feasible
  Mike   28@   78915359   3256H  AK9Z        Not feasible
  NKJ    48!   96754789   8886H  AHBZ        Not feasible
  Adam   18#   78915899   3256H  AK7Z        Not feasible
  Steve  23@   7891HI59   3256H  AK5Z        feasible
  JKN8    35   96451188   3566H  NK4Z        Not feasible
  </code></pre>
  <p><strong>Expected Output Data:</strong></p>
  <pre><code>name   age   Contact    col4   col5  col6  flag
  
  NKJ    48    96754789   8886H  AHBZ        feasible
  Tom    27    98468300   ^686H   ANKZ        feasible
  Mike   28    78915359   3256H  AK9Z        feasible
  NKJ    48    96754789   8886H  AHBZ        feasible
  Adam   18    78915899   3256H  AK7Z        feasible
  Steve  23@    7891HI59   3256H  AK5Z        feasible
  JKN8   35    96451188   3566H  NK4Z        feasible
  </code></pre>
  <p><strong>Script i was trying earlier:</strong></p>
  <pre><code>if flag == 'Not feasible':
    df['age'] = df['age'].replace('[^\d.]', '', regex=True).astype(float)
    df[['col4','col5']] = df[['col4','col5']].apply(lambda x: x.astype(str).str.replace('\W',''))
    df['contact'] = df['contact'].replace('[^\d.]', '', regex=True).astype(float)
    df['flag'] = &quot;feasible&quot;
  </code></pre>
  <p><strong>Modified the script to :</strong></p>
  <pre><code>df1 = df.loc[df['flag'] != 'Not feasible']      
  df = df.loc[df['flag'] == 'Not feasible'].copy()
  
  # Run your cleaning codes with original syntax   
  
  df['age'] = df['age'].replace('[^\d.]', '', regex=True).astype(float)
  df[['col4','col5']] = df[['col4','col5']].apply(lambda x: x.astype(str).str.replace('\W',''))
  df['Contact'] = df['Contact'].replace('[^\d.]', '', regex=True).astype(float)
  df['flag'] = &quot;feasible&quot;
  
  df = pd.concat([df, df1]).sort_index() 
  print(df.head())
  </code></pre>
  <p>Please Suggest.</p>