简体   繁体   English

如何从 python 中的 dataframe 中提取数据(索引)

[英]how to extract data from dataframe in python (Index)

I am trying to take the feature but not getting the results.我正在尝试使用该功能但没有得到结果。

在此处输入图像描述

df_close = df['Close']
df_train = df_close[:'2019-12-31']
df_train.shape

training_set = df_close
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range = (0, 1))
training_set_scaled = sc.fit_transform(training_set)
training_set_scaled[1]

import numpy as np
X_train = []
y_train = []
for i in range(100, training_set.shape[1]): 
  X_train.append(training_set_scaled[i-100:i, 0]) 
  y_train.append(training_set_scaled[i, 0]) 
X_train, y_train = np.array(X_train), np.array(y_train)
X_train

and the result is:结果是:

array([], dtype=float64)

If the value of training_set.shape[1] is smaller then 100 then the inside of the for loop is skipped, leaving X_train empty.如果training_set.shape[1]的值小于100 ,则跳过 for 循环的内部,将X_train留空。

You could test this case by adding a print statement inside the for loop.您可以通过在 for 循环中添加 print 语句来测试这种情况。 Let me know if it worked, good luck!让我知道它是否有效,祝你好运!

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

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