Python 为什么我会得到随机的NAN值
我有一个数据帧,它是移位48个值 我检查了Python 为什么我会得到随机的NAN值,python,pandas,Python,Pandas,我有一个数据帧,它是移位48个值 我检查了numpy数组,它看起来很好:我的意思是它移动了48个位置。现在,我想将数据帧的数据拆分为70:30的比例,以便所有具有nan值的行都位于30%部分 现在,当我打印x\u train时,出于某种原因,我得到了一些带有nan值的行,但我似乎不知道我的代码有什么问题 PS数据是所用api提供的数据帧,不提供nan值 df = pd.DataFrame(data) ## the index is the date and the columns are as
numpy
数组,它看起来很好:我的意思是它移动了48个位置。现在,我想将数据帧的数据拆分为70:30的比例,以便所有具有nan
值的行都位于30%部分
现在,当我打印x\u train
时,出于某种原因,我得到了一些带有nan
值的行,但我似乎不知道我的代码有什么问题
PS数据是所用api提供的数据帧,不提供nan
值
df = pd.DataFrame(data)
## the index is the date and the columns are as prediction,strength,k,g,w
x = np.array(dff.drop(['prediction','strength','g'],1))
y = np.array(dff.drop(['prediction','strength','k'],1))
x_train, x_test, y_train,t_test = train_test_split(x,y, test_size=0.3)
当我试图打印x\u train
时,我得到了所需的值,但其中一些是nan
值,用于'strength'
和'g'
我正在以正确的方式拆分数据,拆分数据后,它是否以任何方式进行排序
x\u列车的一部分
输出:
[78.90399933 nan nan]
[75.04682159 8.51200104 8.16529846]
[78.07499695 nan nan]
[81.23899841 9.76999664 9.13999939]
[80.60099792 8.34100342 8.07700348]
[79.50131226 nan nan]
[72.7118988 4.44860077 7.51000214]
[79.55729675 nan nan]
[74.17259979 5.2460022 7.83300018]
[74.11289978 4.3219986 7.40000153]
[79.62058258 nan nan]
我的请求是输出不带
nan
值的数据。看起来数据在分割之前被洗牌了。因此,如果您希望在没有任何随机性的情况下分割数据,您应该在train\u test\u split
中设置shuffle=False
您能给我们显示df.head(5)
?请