title: Error when trying to apply log method to pandas data frame column in Python
body: <p>So, I am very new to Python and Pandas (and programming in general), but am having trouble with a seemingly simple function. So I created the following dataframe using data pulled with a SQL query (if you need to see the SQL query, let me know and I'll paste it)</p>
  
  <pre><code>spydata = pd.DataFrame(row,columns=['date','ticker','close', 'iv1m', 'iv3m'])
  tickerlist = unique(spydata[spydata['date'] == '2013-05-31'])
  </code></pre>
  
  <p>After that, I have written a function to create some new columns in the dataframe using the data already held in it:</p>
  
  <pre><code>def demean(arr):
      arr['retlog'] = log(arr['close']/arr['close'].shift(1))
  
      arr['10dvol'] = sqrt(252)*sqrt(pd.rolling_std(arr['ret'] , 10 ))  
      arr['60dvol'] = sqrt(252)*sqrt(pd.rolling_std(arr['ret'] , 10 ))  
      arr['90dvol'] = sqrt(252)*sqrt(pd.rolling_std(arr['ret'] , 10 ))  
      arr['1060rat'] = arr['10dvol']/arr['60dvol']
      arr['1090rat'] = arr['10dvol']/arr['90dvol']
      arr['60dis'] = (arr['1060rat'] - arr['1060rat'].mean())/arr['1060rat'].std()
      arr['90dis'] = (arr['1090rat'] - arr['1090rat'].mean())/arr['1090rat'].std()
      return arr
  </code></pre>
  
  <p>The only part that I'm having a problem with is the first line of the function:</p>
  
  <pre><code>arr['retlog'] = log(arr['close']/arr['close'].shift(1))
  </code></pre>
  
  <p>Which, when I run, with this command, I get an error:</p>
  
  <pre><code>result = spydata.groupby(['ticker']).apply(demean)
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>    ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-196-4a66225e12ea&gt; in &lt;module&gt;()
  ----&gt; 1 result = spydata.groupby(['ticker']).apply(demean)
        2 results2 = result[result.date == result.date.max()]
        3 
  
  C:\Python27\lib\site-packages\pandas-0.11.0-py2.7-win32.egg\pandas\core\groupby.pyc in apply(self, func, *args, **kwargs)
      323         func = _intercept_function(func)
      324         f = lambda g: func(g, *args, **kwargs)
  --&gt; 325         return self._python_apply_general(f)
      326 
      327     def _python_apply_general(self, f):
  
  C:\Python27\lib\site-packages\pandas-0.11.0-py2.7-win32.egg\pandas\core\groupby.pyc in _python_apply_general(self, f)
      326 
      327     def _python_apply_general(self, f):
  --&gt; 328         keys, values, mutated = self.grouper.apply(f, self.obj, self.axis)
      329 
      330         return self._wrap_applied_output(keys, values,
  
  C:\Python27\lib\site-packages\pandas-0.11.0-py2.7-win32.egg\pandas\core\groupby.pyc in apply(self, f, data, axis, keep_internal)
      632             # group might be modified
      633             group_axes = _get_axes(group)
  --&gt; 634             res = f(group)
      635             if not _is_indexed_like(res, group_axes):
      636                 mutated = True
  
  C:\Python27\lib\site-packages\pandas-0.11.0-py2.7-win32.egg\pandas\core\groupby.pyc in &lt;lambda&gt;(g)
      322         """
      323         func = _intercept_function(func)
  --&gt; 324         f = lambda g: func(g, *args, **kwargs)
      325         return self._python_apply_general(f)
      326 
  
  &lt;ipython-input-195-47b6faa3f43c&gt; in demean(arr)
        1 def demean(arr):
  ----&gt; 2     arr['retlog'] = log(arr['close']/arr['close'].shift(1))
        3     arr['10dvol'] = sqrt(252)*sqrt(pd.rolling_std(arr['ret'] , 10 ))
        4     arr['60dvol'] = sqrt(252)*sqrt(pd.rolling_std(arr['ret'] , 10 ))
        5     arr['90dvol'] = sqrt(252)*sqrt(pd.rolling_std(arr['ret'] , 10 ))
  
  AttributeError: log
  </code></pre>
  
  <p>I have tried changing the function to np.log as well as math.log, in which case I get the error </p>
  
  <pre><code>TypeError: only length-1 arrays can be converted to Python scalars
  </code></pre>
  
  <p>I've tried looking this up, but haven't found anything directly applicable. Any clues?</p>