简体   繁体   English

如何将目标值设置为熊猫的下一行而不是当前行

[英]How to set target values as next row rather the current row in pandas

I'm creating a basic application to predict the 'Close' value of a stock for day n+1, given features of stock n. 考虑到股票n的特征,我正在创建一个基本应用程序来预测股票n + 1天的“平仓”价值。

I currently define my features and targets as so 我目前已经定义了我的功能和目标

features = df.loc[:,df.columns != 'Close']
targets = df.loc[:,df.columns  == 'Close']

Where targets are the data in the data frame where the column is called 'Close', and the features are those in the data frame where the column isn't called 'Close' 目标是在数据框中将数据列称为“关闭”的数据,特征是在数据框中的数据将列称为“关闭”的数据

This gives me a fairly accurate prediction which would make sense as the Close value is likely to not differ much from the current day's open, low and high values, however I want to use model to predict the value of Close for day n+1, where n is the day, given features in n. 这给了我一个相当准确的预测,这很有意义,因为“关闭”值可能与当天的开盘价,低值和高值相差不大,但是我想使用模型来预测第n + 1天的“关闭”值,其中n是一天,给定n中的特征。

You can apply df_plus1 = df.shift(-1) function from pandas to get the dataframe of the next day. 您可以从pandas应用df_plus1 = df.shift(-1)函数来获取第二天的数据帧。

It would create a df with same dimensions with shifted rows. 它将创建具有相同尺寸的df,并带有移位的行。

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

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