【发布时间】:2016-02-02 17:26:37
【问题描述】:
我有一个 csv 文件,我很确定其中没有 ",我正在尝试使用以下代码读取该文件:
filename_queue = tf.train.string_input_producer(["../data/train_no_empty_rows.txt"])
# train_no_empty_rows
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
record_defaults = [tf.constant(['p'], dtype=tf.string), # Column 0
tf.constant(['p'], dtype=tf.string), # Column 1
tf.constant(['p'], dtype=tf.string)] # Column 2
col1, col2, col3 = tf.decode_csv(
value, record_defaults=record_defaults,field_delim=" ")
features = tf.pack([col2, col3])
with tf.Session() as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1200):
# Retrieve a single instance:
example, label = sess.run([features, col1])
coord.request_stop()
coord.join(threads)
但是当我运行它时,我得到了这个错误:
InvalidArgumentError: Quote inside a string has to be escaped by another quote
[[Node: DecodeCSV_25 = DecodeCSV[OUT_TYPE=[DT_STRING, DT_STRING, DT_STRING],
field_delim=" ",
_device="/job:localhost/replica:0/task:0/cpu:0"]
(ReaderRead_25:1, Const_75, Const_76, Const_77)]]
我想我可以调试,但我找不到它引用 csv 文件中存在问题的条目的位置。这是一个相当大的csv文件,前100个左右的条目没有这个问题。正如我所说,我找不到任何 ", 并且 ' 在测试中似乎解析得很好。有什么方法可以找到麻烦的条目吗?
谢谢!
【问题讨论】:
标签: python csv tensorflow