calculate datetime-difference in years, months, etc. in a new pandas dataframe column

后端 未结 7 2271
长发绾君心
长发绾君心 2021-02-07 05:34

I have a pandas dataframe looking like this:

Name    start        end
A       2000-01-10   1970-04-29

I want to add a new column providing the

7条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 06:09

    A much simpler way is to use date_range function and calculate length of the same

    startdt=pd.to_datetime('2017-01-01')
    enddt = pd.to_datetime('2018-01-01')
    len(pd.date_range(start=startdt,end=enddt,freq='M'))
    

提交回复
热议问题