I have the following dataframe with some dates (datetime64[ns]):
A6U20 A6Z20 A6H21 A6M21 A6U21 A6Z21
expiry 2020-09-14 2020-12-14 2021-03-15 2021-06-14 2021-09-13 2021-12-13
I want to create another dataframe with the number of days between each column and the preceding one. I tried the following:
df2 = (df - df.shift(axis=1))
which resulted in:
A6U20 A6Z20 A6H21 A6M21 A6U21 A6Z21
expiry NaT 91 days 91 days 91 days 91 days 91 days
which is fine, except that I don't need the "days" suffix at the end of each timedelta value. After reading some similar questions, I tried the following command:
df2 = (df - df.shift(axis=1)).dt.days
which resulted in the following error: 'DataFrame' object has no attribute 'dt'.
What am I doing wrong?