I need to to tranform the values in a panda dataframe from timedelta64[ns] to years, but I have that measure in days. For business exigenses I need to express tha measure in years. how could I do ?
I need to to tranform the values in a panda dataframe from timedelta64[ns] to years, but I have that measure in days. For business exigenses I need to express tha measure in years. how could I do ?
You can just divide the timedelta with another timedelta with a length of one year*:
In [1]: import pandas as pd
In [2]: delta = pd.Timedelta('10000000000000000 ns')
In [3]: delta / pd.Timedelta('365 days')
Out[3]: 0.31709791983764585
This really depends on what you are doing with the data. Some examples:
Also, some calendar years have 366 days (when a calendar leap occurs)