In a dataframe that contains prices on Brent per day, I am trying to apply a log function between two consecutive days. I guess the answer is simple but I couldn't find it.
ln[X(i+1)/X(i)] for each line
Thanks in advance for your help
In a dataframe that contains prices on Brent per day, I am trying to apply a log function between two consecutive days. I guess the answer is simple but I couldn't find it.
ln[X(i+1)/X(i)] for each line
Thanks in advance for your help
You can use:
np.log(X.shift(-1) / X)
which shifts the data 1 step back (hence the minus) to get X(i+1) and then divides it by X(i). Lastly, take the log.
Notes:
NaN because there is no i+1th data for themnp.log is the natural logarithm not log10