【发布时间】:2018-11-23 05:52:10
【问题描述】:
我有一个带有日期时间索引的数据框:
time count day hour minute label
2018-06-07 00:25:00 207 7.0 0.0 25.0 177.0
2018-06-07 00:55:00 187 7.0 0.0 55.0 150.0
2018-06-07 01:25:00 194 7.0 1.0 25.0 165.0
2018-06-07 01:55:00 176 7.0 1.0 55.0 175.0
2018-06-07 02:25:00 195 7.0 2.0 25.0 172.0
-> add new datetime record record here
我正在尝试添加一些新记录,但我得到了:
[DatetimeIndex(['2018-06-07 01:55:00'], dtype='datetime64[ns]', name='time', freq=None)] not an index
# this happen even if row exists or not
我只想添加一个30分钟的间隔记录,我的代码是这样的
last_date = recent_posts.iloc[[-1]].index
last_date = last_date + timedelta(minutes=30)
recent_posts.iloc[[last_date]] = # bla #bla
# What I may be doing wrong?
【问题讨论】:
-
您正在寻找不在数据框中的
last_dateDatetimeIndex。 -
是的!当“recent_posts.iloc[[-1]].index”给出最后一个元素时,我认为应该重要的是索引不存在,我想插入一个新行!如果我错了,请纠正我
标签: python pandas datetime dataframe