我正在尝试将dataFrame中列中的数据从数字更改为文本,但到目前为止,我的解决方案不起作用。
示例
# Save results and compute score of probabilities...
id ... categorie_fmc
0 5 ... 1
1 7 ... 1
2 11 ... 1
3 12 ... 1
4 17 ... 0我尝试过的:
finalFile = pd.DataFrame(liste, columns=['id', 'participant','sent','categorie_fmc'])
# view DataFrame
print(finalFile)
# replace
labels = ['Frein', 'Motivation' 'condition']
finalFile['categorie_fmc'] = np.where(finalFile['categorie_fmc'] == 0, labels[0], finalFile['categorie_fmc'])
finalFile['categorie_fmc'] = np.where(finalFile['categorie_fmc'] == 1, labels[1], finalFile['categorie_fmc'])
finalFile['categorie_fmc'] = np.where(finalFile['categorie_fmc'] == 2, labels[2], finalFile['categorie_fmc'])但它不工作,得到这个错误:
IndexError: list index out of range
finalFile['categorie_fmc'] = np.where(finalFile['categorie_fmc'] == 2, labels[2], finalFile['categorie_fmc'])
IndexError: list index out of range
srun: error: r14i5n2: task 0: Exited with exit code 1
srun: Terminating job step 519075.0我所期待的:
# Save results and compute score of probabilities...
id ... categorie_fmc
0 5 ... Motivation
1 7 ... Motivation
2 11 ... Motivation
3 12 ... Motivation
4 17 ... Frein发布于 2021-07-21 17:58:03
尝试使用map函数:
finalFile['categorie_fmc'] = finalFile['categorie_fmc'].map({0: 'Frein', 1: 'Motivation', 2: 'condition'})https://stackoverflow.com/questions/68467496
复制相似问题