【发布时间】:2021-07-06 07:57:36
【问题描述】:
我正在尝试将 csv 文件转换为 numpy 数组。当我试图指定所需的列时,它只是说它在 csv 文件中不存在。所以我检查了 csv 文件,发现 # 被添加到我指定的标题名称中。 无论如何我可以避免这种情况吗?
代码如下
np.savetxt(path13 + 'bkg_sample.csv', predictions, fmt = '%5.5f' ,delimiter = ',' , header='predict')
标题名称 - # predict
jupyter 上的错误 - 'Dataframe' 对象没有属性 'predict'
predict = pd.read_csv('/home/user1/AAAA/Predictions/Code testingbkg.csv',usecols=[2,3,4,5,6,7,8,9,10])
predictions = model.predict(standardscaler.transform(predict))
np.savetxt(path13+'bkg_sample.csv', predictions, fmt = '%5.5f',delimiter = ',',header='predict')
true = pd.read_csv('/home/user1/AAAA/Predictions/bkg_sample.csv')
true[true.predict>0.67] ##This is where the error occurs
图片链接:
bkgsample:https://imgur.com/a/tzh0o2M
predict.csv : https://imgur.com/a/DhPAzqa
【问题讨论】:
-
您尝试重命名列吗?
df.columns = ["a", "b", "c"] -
是的,尝试使用
df.rename(columns = {'# predict' : 'predict'})。没用 -
您好,您能否向我们展示您的预测数组样本并指定其形状,以及 bkg_sample.csv 文件前几行的样本?
标签: python csv machine-learning jupyter-notebook