1

I would like to make a column in existing Pandas df that will be an increment(minutes based, for example) to a set date value, so another words trying to do smth like that:

df_test['date_min'] = datetime.datetime(2019, 3, 1) + pd.to_timedelta(1,unit='min')

I tried this approach and also using for loop but I don't receive an increment just the stable values. How can this task be done in Pandas?

Thanks!

1 Answer 1

3

You could use pd.date_range. Just set an initial datetime, a number of periods to add according to the dataframe's shape and a frequency:

df_test['date_min'] = (pd.date_range(start=datetime.datetime(2019, 3, 1), 
                                     periods=df_test.shape[0], 
                                     freq='min'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.