title: How to apply a function to a certain column by name in a dataframe
body: <p>I have a dataframe with a columns that contain GPS coordinates. I want to convert the columns that are in degree seconds to degree decimals. For example, I have a 2 columns named "lat_sec" and "long_sec" that are formatted with values like 186780.8954N. I tried to write a function that saves the last character in the string as the direction, divide the number part of it to get the degree decimal, and then concatenate the two together to have the new format. I then tried to find the column by its name in the data frame and apply the function to it.</p>
  
  <p>New to python and can't find other resources on this. I don't think I created my function properly. I have the word 'coordinate' in it because I did not know what to call the value that I am breaking down.
  My data looks like this:</p>
  
  <pre><code>long_sec
  635912.9277W
  555057.2000W
  581375.9850W
  581166.2780W
  
  
  df = pd.DataFrame(my_array)
  
  def convertDec(coordinate):
      decimal = float(coordinate[:-1]/3600)
      direction = coordinate[-1:]
      return str(decimal) + str(direction)
  
  df['lat_sec'] = df['lat_sec'].apply(lambda x: x.convertDec())
  
  My error looks like this:
  Traceback (most recent call last):
    File "code.py", line 44, in &lt;module&gt;
      df['lat_sec'] = df['lat_sec'].apply(lambda x: x.convertDec())
    File "C:\Python\Python37\lib\site-packages\pandas\core\frame.py", line 2917, in __getitem__
      indexer = self.columns.get_loc(key)
    File "C:\Python\Python37\lib\site-packages\pandas\core\indexes\base.py", line 2604, in get_loc
      return self._engine.get_loc(self._maybe_cast_indexer(key))
    File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
    File "pandas\_libs\index.pyx", line 129, in pandas._libs.index.IndexEngine.get_loc
    File "pandas\_libs\index_class_helper.pxi", line 91, in pandas._libs.index.Int64Engine._check_type
  KeyError: 'lat_sec'
  </code></pre>