Reputation: 3148
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!
Upvotes: 1
Views: 1498
Reputation: 88226
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'))
Upvotes: 3