如何在 Python 中连接 str 和浮点数



我有 2 个熊猫数据帧,一个带有在 TensorFlow 上工作的神经网络的预测(我猜它们是浮点数(,另一个是每个类的名称(我支持的字符串(,当我尝试这个时

predictions = model.predict_generator(pred_generator, steps=50)
x = pd.DataFrame.from_dict(labels,orient = 'index').index
y = pd.DataFrame(predictions[0])
print(pd.concat(x,y))

我收到此错误

TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid

我正在跳你可以帮助我,在 R 中对我来说会更容易,但我对 Python 没有太多经验,提前谢谢大家

x

不是数据帧,因为您在末尾使用了.index

此外,删除它时出现的错误是因为xy都必须是要concat的第一个参数(在列表或元组中(。试试这个:

x = pd.DataFrame.from_dict(labels,orient = 'index')
y = pd.DataFrame(predictions[0])
print(pd.concat((x,y)))
x = pd.DataFrame.from_dict(labels,orient = 'index')
y = pd.DataFrame(predictions[0])
print(np.column_stack((x,y)))

相关内容

最新更新