如何读取tensorflow中的字符串和长特征

时间:2016-09-17 14:16:50

标签: python csv tensorflow

张量流,我读不到字符串,长,只允许短浮点数?为什么?

import tensorflow as tf
import numpy as np

# Data sets
IRIS_TRAINING = "seRelFeatures.csv"
IRIS_TEST = "seRelFeatures.csv"

# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING, target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TEST, target_dtype=np.int)

这是错误

/home/xuejiao/anaconda2/bin/python /home/xuejiao/Desktop/HDSO_DirectAnswer/training_testing/dnn_semiSuper.py
Traceback (most recent call last):
  File "/home/xuejiao/Desktop/HDSO_DirectAnswer/training_testing/dnn_semiSuper.py", line 9, in <module>
    training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING, target_dtype=np.int)
  File "/home/xuejiao/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py", line 47, in load_csv
    target[i] = np.asarray(ir.pop(target_column), dtype=target_dtype)
  File "/home/xuejiao/anaconda2/lib/python2.7/site-packages/numpy/core/numeric.py", line 482, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: invalid literal for long() with base 10: ''

Process finished with exit code 1

2 个答案:

答案 0 :(得分:0)

您的错误是ValueError: invalid literal for long() with base 10: ''。它只是输入空字符串而不是整数(或整数的字符串表示)。我会检查CSV文件中的数据。

答案 1 :(得分:0)

其实我自己解决了这个问题,这个错误意味着

ValueError: invalid literal for long() with base 10: ''

我有一些空单元格,但实际上我没有查看。 我检查后,它通过我删除最后一列,但我只是删除内容没有删除单元格,所以从视图中找不到任何空