TypeError: '(slice(0, 201617, 1), slice(None, None, None))' 是无效键

pet*_*nce 0 numpy pandas tensorflow

读取以下数据后:

Head:
          Open       Close        High         Low       Volume   volume_adi   volume_obv  volume_obvm  ...  momentum_stoch  momentum_stoch_signal  momentum_wr  momentum_ao  others_dr  others_dlr  others_cr   nextClose
0  118.940002  118.950996  119.015999  118.926003  3468.199951 -1468.002197     0.000000     0.000000  ...       27.777779              27.777779   -72.222221     0.000000  14.749734    0.000000   0.000000  118.948997
1  118.954002  118.959000  118.974998  118.892998  3083.300049  1139.846680  3083.300049    -8.533334  ...       53.658535              35.663956   -46.341465     0.000000   0.008407    0.008407   0.006725  118.975998
2  118.966003  118.975998  118.990997  118.922997  2914.600098  3508.808105  2914.600098   722.250000  ...       67.479675              48.897923   -32.520325     0.000000   0.014291    0.014290   0.021017  118.985001
3  118.992996  118.985001  119.000000  118.967003  3088.800049  1909.547119  3088.800049  1195.560059  ...       74.796745              65.311653   -25.203253     0.000000   0.007565    0.007564   0.028583  118.987999
4  118.987999  118.987999  119.001999  118.953003  3175.399902  1641.685669  3175.399902  1525.533325  ...       77.235771              73.170731   -22.764227    -0.001633   0.002521    0.002521   0.031105  118.984001
Run Code Online (Sandbox Code Playgroud)

像这样:

column_names = ['Open', 'Close', ... , 'others_cr', 'nextClose']
dataset = pd.read_csv(dataset_path, names=column_names,
                      na_values = '?', comment='\t', index_col=False,
                      sep=',', skipinitialspace=True, skiprows=[1], dtype='float32')

print('Head:\n {}'.format(dataset.head()))
Run Code Online (Sandbox Code Playgroud)

尝试拆分数据并添加新维度时出现以下错误,例如:

train_size = int(len(dataset) * 0.67)
train_dataset = dataset[0:train_size,:]
Run Code Online (Sandbox Code Playgroud)

错误:

TypeError: '(slice(0, 201617, 1), slice(None, None, None))' is an invalid key
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,提前致谢。

pet*_*nce 5

我试图使用numpy分割技术通过使用pandas.dataframe 以下方法将其转换dataframenumpy数组来解决它:

dt = dataset.values
dt = dt.astype('float32')
train_size = int(len(dt) * 0.67)
train_dataset = dt[0:train_size,:]
Run Code Online (Sandbox Code Playgroud)