我自己会问chatGPT 2021-12-16 23:49 采纳率: 42.9%
浏览 200
已结题

TypeError: string indices must be integers


def load_data(self):
        reviews = pd.read_csv('tuniu.csv')  
        data = reviews['content']
        #with open('r.json') as file:
           #data = file.read()
        #data = json.loads(data)
        #print(type(data))
        return data

    def fenci_data(self):
            text = []
            data = self.load_data()
            with open("stoplist.txt", 'r',encoding='UTF-8') as file:
                stop_word_list = file.read()
            for weibo_item in tqdm(data):
                tmp = []
                sentence=''.join(re.findall(r'[\u4e00-\u9fa5]+',weibo_item['content']))
                for word in jieba.lcut(sentence):
                    if word not in stop_word_list:
                        tmp.append(word)
                text.append(tmp)
            return text

报错:
sentence=''.join(re.findall(r'[\u4e00-\u9fa5]+',weibo_item['content']))
TypeError: string indices must be integers

  • 写回答

4条回答 默认 最新

  • 陈年椰子 2021-12-17 11:03
    关注

    那就是只传 content 这一列而已。

    sentence=''.join(re.findall(r'[\u4e00-\u9fa5]+',weibo_item['content']))
    
    # 改为
    
    sentence=''.join(re.findall(r'[\u4e00-\u9fa5]+',weibo_item))
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月17日
  • 已采纳回答 12月17日
  • 创建了问题 12月16日