【发布时间】:2017-12-02 12:38:42
【问题描述】:
当我尝试接收 csv 文件中的数据时出现此错误:
InvalidArgumentError(参见上面的回溯):记录 0 中的字段 0 是 不是有效的 int32:符号 [[节点:DecodeCSV = 解码CSV[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, 解码CSV/record_defaults_6)]]
数据是Symbol,Date,Open,High,Low,Close,Volume的列 AAB.TO,23-Jun-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)
如何修复错误?
【问题讨论】:
标签: python csv tensorflow