1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Add monthly increments to a datetime column in pandas [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I have the following dataset and I simply want to add the monthly increments to my date column.

    index monthly_increment date
    0 1 2018-12-01
    1 2 2018-10-01
    2 3 2018-12-01
    3 4 2018-01-01
    4 5 2018-06-01


    I'm hoping to get a new column:


    index new_date
    0 2019-01-01
    1 2018-12-01
    2 2019-03-01
    3 2018-05-01
    4 2018-11-01


    When I try using DateOffset I get a TypeError.

    >> df['new_date'] = df['date']+ pd.DateOffset(df['monthly_increment'])

    TypeError: `n` argument must be an integer, got <class 'pandas.core.series.Series'>


    Is there any simple solution to this?

    Continue reading...

Compartilhe esta Página