Operations with dates

0

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
    
asked by efueyo 09.08.2018 в 23:46
source

1 answer

0

When you talk about "converting dates into numbers to perform arithmetic operations, just as Excel executes them", I guess what you want to say is how to know the days elapsed between two dates given.

For example, to calculate the days and seconds elapsed between 1/12/1999 and today:

from datetime import datetime

fecha1 = datetime(1999, 12, 1)
fecha2 = datetime.now()

diferencia = fecha2 - fecha1

print("días transcurridos....: %d" % diferencia.days)
print("segundos transcurridos: %d" % diferencia.seconds)
    
answered by 12.08.2018 / 19:12
source