dfMain是一个大数据帧,根据某些条件从中创建df1。dfMain的索引是唯一的时间戳。
由于pandas.dataframe.index.get_loc函数一次仅获取一个值,因此以下代码可以向量化吗?
df1 = dfMain[(dfMain['colX'] == 1) &
(dfMain['date_minute'].dt.time < pd.Timestamp('10:00').time())]
# make a list containing the indices
nextRow = []
for row in df1.itertuples(index=True):
nextRow.append(dfMain.index.get_loc(row.Index))
# get the subsequent row
nextRow = np.array(nextRow) + 1
我尝试了numpy.where:
np.where(df1['date_minute'] == dfMain['date_minute'])
但这会引发错误Can only compare identically-labeled Series objects