Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在数据帧的开头插入列向量?_Python_Pandas_Numpy - Fatal编程技术网

Python 如何在数据帧的开头插入列向量?

Python 如何在数据帧的开头插入列向量?,python,pandas,numpy,Python,Pandas,Numpy,我有以下两个变量: print('Column vector type %s and shape %s' % (type(target), target[0:X_train.shape[0]].shape)) print('Data frame type %s and shape %s' % (type(X_train), X_train.shape)) 这就产生了: Column vector type <class 'numpy.ndarray'> and shape (871

我有以下两个变量:

print('Column vector type %s and shape %s' % (type(target), target[0:X_train.shape[0]].shape))
print('Data frame type %s and shape %s' % (type(X_train), X_train.shape))
这就产生了:

Column vector type <class 'numpy.ndarray'> and shape (87145,)
Data frame type <class 'pandas.core.frame.DataFrame'> and shape (87145, 11)
我想插入目标列向量作为此帧/矩阵的第一列。。。我该怎么做

我的最终目标是能够使用corr函数计算附加到预测变量或设计矩阵的响应变量的相关矩阵

使用:

对于指定与DataFrame相同长度的数组:

X_train.insert(0,'target',target) 
print (X_train)
X_train.insert(0,'target',target[:X_train.shape[0]]) 
print (X_train)