Pandas - Number of Months Between Two Dates - Stack Overflow

PHOTO EMBED

Wed May 12 2021 08:50:10 GMT+0000 (UTC)

Saved by @arielvol

df.assign(
    Months=
    (df.Date2.dt.year - df.Date1.dt.year) * 12 +
    (df.Date2.dt.month - df.Date1.dt.month)
)

       Date1      Date2  Months
0 2016-04-07 2017-02-01      10
1 2017-02-01 2017-03-05       1
content_copyCOPY

https://stackoverflow.com/questions/42822768/pandas-number-of-months-between-two-dates