【问题标题】:Using a sampling of a datetime index to select the features (rows) in a pandas dataframe at those datetimes使用日期时间索引的采样在这些日期时间选择熊猫数据框中的特征(行)
【发布时间】:2019-01-12 08:34:32
【问题描述】:

我有一个日期时间索引对象,它由我正在训练学习者的 LARGER 数据帧中随机抽样数据的索引值组成。我想使用日期时间索引,例如

DatetimeIndex(['1911-11-18', '2015-05-02', '1934-08-15', '1950-09-16',
               '1944-06-01', '2004-07-30', '1947-11-18', '1977-07-08',
               '1945-05-31', '1944-01-31',
               ...
               '1884-06-24', '1999-11-22', '1960-02-02', '1883-03-08',
               '1952-11-19', '1993-02-04', '1965-04-26', '1885-09-30',
               '1890-02-26', '2008-03-28'],
              dtype='datetime64[ns]', length=300000, freq=None)

每个训练示例返回完整的数据框并查找那些日子的目标值,然后从该日期开始往后 1 年用作真正的目标。

整体上下文是对来自时间序列数据的随机样本进行训练,并以未来的值为目标。

我的大数据框叫做 toLearn。我正在训练的示例数据框称为 dataSlice(toLearn 的子集)。

【问题讨论】:

标签: python pandas dataframe time-series


【解决方案1】:

以下内容适用于我正在尝试做的事情。

 # Find Target 7 years after Each Training Sample 

indicesOfTrainSamples=trainSamples.index
indicesOfTarget=indicesOfTrainSamples + pd.Timedelta(weeks=7*52)

targets=[]
for i in indicesOfTarget:
     targets.append(toLearn.loc[i])

targetSlices=pd.DataFrame(targets,index=indicesOfTarget)
targetFeature=targetSlices['targetValues']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-16
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    相关资源
    最近更新 更多