【发布时间】:2020-04-03 22:43:36
【问题描述】:
我正在尝试构建一个项目并创建一个包含 13347 行和 2500 列的 csv,但在通过 pandas 读取文件期间,仅读取了初始 6600 个值,因此我的模型构建不正确。请告诉我为什么会发生这种情况以及我该如何解决。我正在附加一部分带有输出的代码。
**Code:**
data=pd.read_csv("train_foo.csv",low_memory=False)
dataset=np.array(data)
print(dataset.shape)
np.random.shuffle(dataset)
x=dataset
y=dataset
x=x[:,1:2501]
y=y[:,0]
**#splitting the data into training and testing set, normalizing the values**
x_train=x[0:12000,:] # 12000 samples in training set
x_train=x_train/255. # coverting the pixel values0-255 into 0-1
x_test=x[12001:13345,:] # 1345 samples in testing set
x_test=x_test/255.
y=y.reshape(y.shape[0],1)
y_train=y[0:12000,:]
y_train=y_train.T
y_test=y[12001:13345,:]
y_test=y_test.T
print("no. of training examples:"+str(x_train.shape[0]))
print("no. of test examples:"+str(x_test.shape[0]))
print("x_train shape:"+ str(x_train.shape))
print("x_test shape:"+ str(x_test.shape))
print("y_train shape:"+str(y_train.shape))
print("y_test shape: "+str(y_test.shape))
**output:**
no. of training examples:6672
no. of test examples:0
x_train shape:(6672, 2500)
x_test shape:(0, 2500)
y_train shape:(1, 6672)
y_test shape: (1, 0)
【问题讨论】:
-
我在我的系统上运行了上面的代码段,它运行良好。请检查您的案例中代码的其他部分是否未修改变量。
-
Ya 代码没有显示任何错误,它仅重新定位 csv 文件的初始 6675 行,其余行未读取
-
在我的系统中,行数上升到 12000。尝试在您的系统上运行此代码段并让我们知道结果。我用随机数据创建了一个类似的数据框。 codeshare.io/2WwjAv
-
谢谢,但我已经重新检查过,变量没有变化......我也更新了熊猫,但它仍然没有完全读取 csv 文件
-
我什至试图分块阅读它,但仍然没有完全阅读。难道只有csv文件有问题吗
标签: python pandas numpy csv tensorflow