当我读取下一个入口的csv文件时 2,3,“ ['Action','Children']” 我想将第三个entrace读为带有两个字符串的张量,但是当我使用
时tf.decode_csv('2,3,"['Action','Children']" ',[0,0,""])
当前结果是:
b"['Action','Children']"
如何获得结果:
tf.string ["Action","Children"] shape=(1,)
我想将其用作cathegorical_features
。
答案 0 :(得分:0)
我以这种方式解决:
CSV_COLUMNS=["Int1","Int2","genre"]
DEFAULTS=[0,0,["Unknown"]]
columns = tf.decode_csv('2,3,"['Action','Children']" ', record_defaults=DEFAULTS)
features = dict(zip(CSV_COLUMNS, columns))
features["genre"]=tf.regex_replace(features["genre"],pattern="\[",rewrite="")
features["genre"]=tf.regex_replace(features["genre"],pattern="\]",rewrite="")
features["genre"]=tf.regex_replace(features["genre"],pattern="\'",rewrite="")
features["genre"]=tf.strings.split(features["genre"],sep=",",result_type="RaggedTensor")