I have a DataFrame ( df
), in which the dates are in the format datetime64(ns)
(2017-09-18). I need to implement the following statement in a Python script:
Fech_Act = pd.Timestamp("2018-08-02")
df["TAE"] = ((1 +((df["Val_Act"]/df["Imp_Inv"])^(1/df["Fech_Act"] - Fech_Inv))-1))^365-1
Its execution returns the error
TypeError: cannot perform __rtruediv__ with this index type: DatetimeIndex
How can I solve this problem?
Is there any way to convert dates into numbers to perform arithmetic operations, as Excel executes them?
I tried this option.
import arrow
df["TAE"] = ((1 +((df["Val_Act"]/df["Imp_Inv"])^(1/arrow.get(df["Fech_Inv"]) - Fech_Act))-1))^365-1
I get the error back
TypeError: Can't parse single argument type of '<class 'pandas.core.series.Series'>'
I've tried with this other option
from datetime import datetime
date_format = "%Y-%m-%d"
Fech_Act = datetime.strptime("2018-08-02", date_format)
df["TAE"] = ((1 +((df["Val_Act"]/df["Imp_Inv"])^(1/ datetime.strptime(df["Fech_Inv"],date_format) - Fech_Act))-1))^365-1
Also without success. He returns me.
TypeError: strptime() argument 1 must be str, not Series
The final solution has been:
# Calcular TAE:
diferencia = fech_fin-fech_ini
TAE = (1+((cotz_fin*opcion/cotz_ini*opcion)**(1/diferencia.days)-1))**365-1
TAE