Python pandas has a pct_change function which I use to calculate the returns for stock prices in a dataframe:
ndf[\'Return\']= ndf[\'TypicalPrice\'].pct_chan
Single line, and only calculating logs once. First convert to log-space, then take the 1-period diff.
np.diff(np.log(df.price))
In earlier versions of numpy:
np.log(df.price)).diff()