我想阅读大量数据集: aab,20170525,0.13,0.14,14,0.13,0.14.14,2060,等等。
import tensorflow as tf
filename_queue = tf.train.string_input_producer(["D:/data/20170623.csv"])
reader = tf.TextLineReader(skip_header_lines=1)
key, value = reader.read(filename_queue)
record_defaults = [tf.constant([], dtype= tf.int32),
tf.constant([], dtype= tf.int32),
tf.constant([], dtype=tf.int32),
tf.constant([], dtype=tf.int32),
tf.constant([], dtype=tf.int32),
tf.constant([], dtype=tf.int32),
tf.constant([], dtype=tf.int32)]
col1, col2, col3, col4, col5, col6, col7 = tf.decode_csv(value, record_defaults=record_defaults)
assert col1.dtype == tf.int32
assert col2.dtype == tf.int32
assert col3.dtype == tf.int32
assert col4.dtype == tf.int32
assert col5.dtype == tf.int32
assert col6.dtype == tf.int32
assert col7.dtype == tf.int32
features = tf.stack([tf.to_string(col1), tf.to_string(col2)])
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(1200):
# Retrieve a single instance:
example, label = sess.run([features, col1])
coord.request_stop()
coord.join(threads)
错误:
Traceback (most recent call last):
File "<ipython-input-18-8079bf3fc932>", line 1, in <module>
runfile('D:/data/temp.py', wdir='D:/data')
File "D:Anacondaenvstensorflowlibsite-packagesspyderutilssitesitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "D:Anacondaenvstensorflowlibsite-packagesspyderutilssitesitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/data/temp.py", line 33, in <module>
features = tf.stack([tf.to_string(col1), tf.to_string(col2)])
AttributeError: module 'tensorflow' has no attribute 'to_string'
如何从CSV文件返回基于名称的值?包含日期,单词,值,浮子?
感谢您的帮助。
您应该通过更改record_defaults
张量来指定tf.decode_csv
步骤中正确的dtype
,以便TensorFlow知道它应该给每列的dtype
。这样,您就无需更改之后。
例如。您可以做这样的事情:
record_defaults = [[''],
[''],
[0.0],
[0.0],
[0.0],
tf.constant([], dtype=tf.int32),
tf.constant([], dtype=tf.int32)]
一种解决方案是导入pandas。
如果您使用的是Anaconda。
conda install -c anaconda pandas=0.20.2
等到安装熊猫,或在anaconda> tensorflow下搜索熊猫。
代码是:
import pandas as pd
df=pd.read_csv("csvdirectoryhere")
print(df)
如果您有多个数据集,则要导入Python,则可以将DF更改为DF1。print(df1(df1 = pd.read_csv(" csvdirectoryhere"(df1等。
要使用所导入的数据,您可以执行类似的操作,也可以关注文档。
特别感谢所有回答我的问题的人。