简体   繁体   English

将递增日期值添加到Pandas中的列

[英]Adding incrementing date value to a column in Pandas

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中创建一列,将其增加(例如,以分钟为基础)到设置的日期值,因此,另一个尝试这样做的词是:

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. 我尝试了这种方法,也使用了for循环,但仅稳定值我没有收到增量。 How can this task be done in Pandas? 如何在熊猫中完成这项任务?

Thanks! 谢谢!

You could use pd.date_range . 您可以使用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'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM