python 对文本数据关键词提取时出现错误

zhangzheny 2016-05-12 02:13:22
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pandas as pd
import numpy as np
import jieba
import nltk
import jieba.posseg as pseg

df = pd.read_csv('D:\csv_test.csv',names=['id','cont','type'])

cont = df['cont']
tagall=[]
for t in cont:
tags = jieba.analyse.extract_tags(t,10)
tagall.append(tags)
dist = nltk.FreqDist(tagall)
fea_words = dist.keys()[:100]
print fea_words

出现:E:\Python27\python.exe C:/Users/Administrator/PycharmProjects/Ma/m1.py
sys:1: DtypeWarning: Columns (1) have mixed types. Specify dtype option on import or set low_memory=False.
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/Ma/m1.py", line 14, in <module>
tags = jieba.analyse.extract_tags(t,1)
AttributeError: 'module' object has no attribute 'analyse'
怎么解决???

...全文
4781 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
屎克螂 2016-05-16
  • 打赏
  • 举报
回复
tags = jieba.analyse.extract_tags(str(t), 1)
zhangzheny 2016-05-12
  • 打赏
  • 举报
回复
引用 2 楼 panghuhu250 的回复:
加上

import jieba.analyse
E:\Python27\python.exe C:/Users/Administrator/PycharmProjects/Ma/m3.py sys:1: DtypeWarning: Columns (1) have mixed types. Specify dtype option on import or set low_memory=False. Building prefix dict from the default dictionary ... Loading model from cache c:\users\admini~1\appdata\local\temp\jieba.cache Loading model cost 0.688 seconds. Prefix dict has been built succesfully. Traceback (most recent call last): File "C:/Users/Administrator/PycharmProjects/Ma/m3.py", line 18, in <module> tags = jieba.analyse.extract_tags(t, 1) File "E:\Python27\lib\site-packages\jieba\analyse\tfidf.py", line 94, in extract_tags for w in words: File "E:\Python27\lib\site-packages\jieba\__init__.py", line 282, in cut sentence = strdecode(sentence) File "E:\Python27\lib\site-packages\jieba\_compat.py", line 37, in strdecode sentence = sentence.decode('utf-8') AttributeError: 'long' object has no attribute 'decode' 什么情况
panghuhu250 2016-05-12
  • 打赏
  • 举报
回复
加上

import jieba.analyse
关山路遥 2016-05-12
  • 打赏
  • 举报
回复
重新安装一下jieba试试

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧