m0_61104322
2022-04-26 17:36
采纳率: 88.2%
浏览 507

'list' object has no attribute 'values'

运行fasttext形成文本的时候,出现了下面的问题:

# coding=utf-8
import pandas as pd
import numpy as np
import fasttext
from sklearn import metrics

with open('train_abstract.txt','w',encoding='utf-8') as f:
    for i in range(len(X_train.todense())):
        str1 = str(X_train.todense()[i])+"\t"+"__label__"+str(y_train.values[i])+'\n'
        f.write(str1)

with open('test_abstract.txt','w',encoding='utf-8') as f:
    for i in range(len(X_test)):
        str1 = str(X_test.values[i])+"\t"+"__label__"+str(y_test.values[i])+'\n'
        f.write(str1)

AttributeError                            Traceback (most recent call last)
<ipython-input-38-1b98cdb96387> in <module>()
      7 with open('train_abstract.txt','w',encoding='utf-8') as f:
      8     for i in range(len(X_train.todense())):
----> 9         str1 = str(X_train.todense()[i])+"\t"+"__label__"+str(y_train.values[i])+'\n'
     10         f.write(str1)
     11 

AttributeError: 'list' object has no attribute 'values'

请教大家如何解决这个问题。

5条回答 默认 最新

相关推荐 更多相似问题