我正在读取以下(csv)文件作为我的jupyter笔记本中的数据帧:
name,gender,type,currency,age,id,sessions,amount,averageSessionDuration,numberOfActiveDays
"OjkTPVONFUTLyR","M","test","GBP",20,1247084,126,3759.799995016699,422.2407336248684,10
下面是读取该文件的代码:
df = pd.read_csv(
tf.gfile.Open("/data/historical.csv"),
skipinitialspace=True)
我有一个列名数组,并尝试将这些值映射到tensorflow常量中,例如:
CONTINUOUS_COLUMNS = ["age", "id", "sessions", "amount", "averageSessionDuration", "numberOfActiveDays"]
continuous_cols = {k: tf.constant(df[k].values) for k in CONTINUOUS_COLUMNS}
在执行此操作时,我收到以下错误:
TypeError: Expected binary or unicode string, got 20.0
因此,它看起来不能从值派生类型(对于age列)。我还需要做什么才能让它工作吗?
Tensorflow版本:1.13.0-rc1
Pandas版本:0.24.1
Docker镜像:tensorflow/tensorflow:latest-py3-jupyter
发布于 2019-02-21 02:30:59
我刚运行了你的代码。您在下面的代码行中将密钥amount
错误地设置为amounts
。
CONTINUOUS_COLUMNS = ["age", "id", "sessions", "amounts", "averageSessionDuration", "numberOfActiveDays"]
更正此错误后,对于python-2.7和python-3.5都没有给出任何错误
我的熊猫版本:0.23.4
和tensorflow版本:1.10.1
https://stackoverflow.com/questions/54792795
复制相似问题