Skip to content
Advertisement

Adding different days in a DataFrame with a fixed date

I have a DataFrame with numbers (‘number’) and I wanted to add these numbers to a date. Unfortunately my attempts don’t work and I always get error messages no matter how I try….

This is a code example how I tried it:

JavaScript

As an example of the result (YYYY/MM/DD) should come out a column or DataFrame with a date, which results from the calculation “start date + number”.

JavaScript

Currently the numbers are in the df ‘number’ type object. Then I get this error message.

JavaScript

If I change df ‘number’ to str or int64, I get this error message.

JavaScript

What am I doing wrong or can someone help me?

Thanks a lot!

Advertisement

Answer

If need add days by original column to 2010-01-01 use to_datetime:

JavaScript

For format YYYY/MM/DD add Series.dt.strftime:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement