I'm working with time series data and have transformed numbers to logarithmic differences with numpy
.
df['dlog']= np.log(df['columnx']).diff()
Then I made predictions with that transformation.
How can I return to normal numbers?
columnx
still exists in df
.diff()
calculates the difference of a Series element compared with another
element in the Series.
dlog
is NaN
. Without a "base" number (e.g. np.log(764677)
) there is not a way to step back that transformationdf = pd.DataFrame({'columnx': [np.random.randint(1_000_000) for _ in range(100)]})
df['dlog'] = np.log(df.columnx).diff()
columnx dlog
764677 NaN
884574 0.145653
621005 -0.353767
408960 -0.417722
248456 -0.498352
np.log
with np.exp
np.exp
to transform from a logarithmic to linear scale.df = pd.DataFrame({'columnx': [np.random.randint(1_000_000) for _ in range(100)]})
df['log'] = np.log(df.columnx)
df['linear'] = np.exp(df.log)
columnx log linear
412863 12.930871 412863.0
437565 12.988981 437565.0
690926 13.445788 690926.0
198166 12.196860 198166.0
427894 12.966631 427894.0
np.log