当我尝试在csv文件中接收数据时出现此错误:
InvalidArgumentError(参见上面的回溯):记录0中的字段0是 不是有效的int32:符号[[Node:DecodeCSV = DecodeCSV [OUT_TYPE = [DT_INT32,DT_INT32,DT_INT32,DT_INT32,DT_INT32, DT_INT32,DT_INT32],field_delim =“,”, _device =“/ job:localhost / replica:0 / task:0 / cpu:0”](ReaderReadV2:1,DecodeCSV / record_defaults_0,DecodeCSV / record_defaults_1, DecodeCSV / record_defaults_2,DecodeCSV / record_defaults_3, DecodeCSV / record_defaults_4,DecodeCSV / record_defaults_5, DecodeCSV / record_defaults_6)]]
数据是符号,日期,打开,高,低,关闭,体积的列 AAB.TO,23君2017,0.13,0.13,0.13,0.13,500
import tensorflow as tf
tf.reset_default_graph()
filename_queue = tf.train.string_input_producer(["D:\data\TSX_20170623.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[1], [1], [1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5, col6, col7 = tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.stack([col1, col2, col3, col4, col5, col6, col7])
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(12):
# Retrieve a single instance:
Symbol, label = sess.run([features, col7])
coord.request_stop()
coord.join(threads)
如何修复错误?
答案 0 :(得分:1)
根据你所说的,你的csv文件有header_lines(符号,日期,开放,高,低,关等等)。
TextLineReader() Tensorflow的读者可以使用参数( skip_header_lines )让您决定是否要跳过第一行,即标题行与否。 默认情况下,参数默认设置为None。 https://www.tensorflow.org/api_docs/python/tf/TextLineReader#reader_ref
您应该将其设置为1,以忽略标题行。
reader = tf.TextLineReader(skip_header_lines=1)