title: How to execute the script inside a function
body: <p>I am trying to execute the code inside a function, Which can be used anywhere within the environment but its not working, and giving the Error.</p>
  <blockquote>
  <p>But when i am using the same code without any function it's working fine. i don't understand why is not working when trying to execute within a function</p>
  </blockquote>
  <p><strong>Input Data</strong></p>
  <pre><code>Col1
  U_a65839_Jan87Apr88
  U_b98652_Feb88Apr88_(2).jpg.pdf
  V_C56478_mar89Apr89
  NaN
  Q_d15634_Apr90Apr91
  Q_d15634_Apr90Apr91_(3).jpeg.pdf
  S_e15336_may91Apr93
  NaN
  </code></pre>
  <p><strong>Expected Output:</strong></p>
  <pre><code>col2          start_dt     end_Dt
  Jan87Apr88    Jan1987      Apr1988
  Feb88Apr88    Feb1988      Apr1988
  mar89Apr89    mar1989      Apr1989
  Apr90Apr91    Apr1990      Apr1991
  Apr90Apr91    Apr1990      Apr1991
  may91Apr93    may1991      Apr1993
  </code></pre>
  <p><strong>Code I have been using</strong></p>
  <pre><code>def newmap(x):
      try:
          df['col2'] = df.col1.str.split(&quot;_&quot;, expand=True)[2]
          # split first part
          df['start_dt'] = df.File_Path.str[:5]
          # split second part
          df['end_dt'] = df.File_Path.str[5:10]
          # add 19
          df['start_dt'] = df.start_dt.replace({'(\d\d)': r'19\1'}, regex=True)
          df['end_dt'] = df.end_dt.replace({'(\d\d)': r'19\1'}, regex=True)
  
      except ValueError:
          df['status'] = ValueError
  
  
      return df
  
  df = newmap(df) 
  </code></pre>
  <p>While Running the above code getting the error</p>
  <blockquote>
  <p>AttributeError: 'Series' object has no attribute 'col1'</p>
  </blockquote>
  <p>Please Suggest.</p>