Python--使用jieba进行分词并计算词权重

2023-05-16

import jieba
import xlrd
import jieba.analyse

def stopwordslist(filepath):
    stopwords = [line.strip() for line in open(filepath, 'r', encoding='utf-8').readlines()]
    return stopwords

def fenci(content):
    table = content.sheets()[0]
    nrows = table.nrows#获取行数
    row1=1
    cell=""
    final = ""
    while row1<nrows:
        cell = table.cell(row1,0).value
        fenci=jieba.cut(cell)

        for seg in fenci:

            if seg not in stopwords and len(seg)>0:
                final+=seg+" "
                final+=""
        final+='\n'
        # print(row1,final)
        row1 += 1

    return final

jieba.load_userdict("C:\\Users\\Administrator\\Desktop\\userdic.txt")#导入自定义词典,自定义词典编码方式为UTF-8
stopwords=stopwordslist("C:\\Users\\Administrator\\Desktop\\stop.txt")#导入停止词典

content=xlrd.open_workbook("C:\\Users\\Administrator\\Desktop\\zhaopin_data.xlsx")#导入数据
final=fenci(content)
# print(final)

keywords = jieba.analyse.extract_tags(final,topK=200,withWeight=True,allowPOS=())
# print(keywords)
for item in keywords:
    # if item[0] in ("SQL","Python","SAS"):
        print(item[0], item[1])  # 输出关键词和相应的权重


#可根据输出的topK词语,再挑选一些加入停止词典中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python--使用jieba进行分词并计算词权重 的相关文章

随机推荐

  • postgresql时间戳与时间的转换

    日期转时间戳 span class token keyword select span EXTRACT span class token punctuation span epoch span class token keyword FRO
  • python xml文件解析

    1 解析 1 1 解析方式 Python 有三种 XML 解析方式 xff1a SAX xff08 simple API for XML xff09 DOM xff08 Document Object Model xff09 Element
  • python输出列表去掉中括号

    可以使用 join的方法进行输出 xff0c 因为 join处理的是字符串 xff0c 所以需要进行类型转换 list1 span class token operator 61 span span class token punctuat
  • postgresql取出分组的第一条数据

    span class token comment 根据编号分组后取第一条数据 span span class token keyword SELECT span span class token operator span span cla
  • git 清空本地修改

    span class token function git span checkout span class token keyword span span class token comment 本地所有修改的 没有的提交的 xff0c
  • 关于Ubuntu卸载Python导致的终端没了

    解决方式 sudo upgrade fix missing sudo apt install ubuntu desktop
  • elasticsearch wildcard查询取消大小写

    https stackoverflow com questions 51107349 elasticsearch wildcard case sensitive 添加case insensitive 参数即可 GET test 005 se
  • window VNC Viewer设置屏幕分配率

    问题 xff1a 远程时 xff0c 显示的界面不会跟着本机屏幕大小而自动调节 xff0c 导致无法在页面中完全显示屏幕的内容 解决1 xff1a 打开VNC Viewer xff0c 选择Options xff0c 在Scale to w
  • .net core 中使用MongoDB

    https www thecodebuzz com exception filters in net core https www mongodb com docs drivers csharp https www mongodb com
  • 使用代理下载国外源registry.k8s.io镜像,并传到docker hub私有镜像库

    日常的生产开发中 xff0c 免不了从国外拉取镜像 xff0c 但有个问题 xff0c 我们可能访问不到那个镜像源 xff0c 因此需要使用代理 https labs play with docker com 具体步骤 使用docker h
  • python 操作neo4j

    安装依赖包 pip span class token function install span neo4j 使用 span class token keyword class span span class token class nam
  • neo4j获取不同维度关联关系

    插入数据 CREATE span class token punctuation span 小北 朋友圈 span class token punctuation span 姓名 span class token string 34 小北
  • neo4j结合gds实现最短路径算法

    背景 xff1a Neo4j自带的cypher语句中的 shortestpath allShortestPaths 返回值内容非常有限 xff0c 不易处理 在实际生产环境中可用性极低 xff0c 且若带where条件查询时 xff0c 查
  • C#解决中文乱码

    字符串乱码 可以使用Regex Unescape函数解决 字符串写入文件乱码 使用File AppendAllText 或者File WriteAllText path string Encoding ASCII
  • JS中的异步详解

    一 xff1a 异步是什么 xff1f 同步和异步是两种模式 34 同步模式 34 就是指后一个任务等待前一个任务结束 xff0c 然后再执行 xff0c 程序的执行顺序与任务的排列顺序是一致的 同步的 34 异步模式 34 则完全不同 x
  • C语言截取某个字符之前的字符串

    uint32 size 61 0 int p char str 61 34 fadhjkfhadl fhdjfkhla dfjkadlf 34 char str2 61 34 34 p 61 0 for int k 61 0 strlen
  • Xlib: extension “XInputExtension“ missing on display “:1.0“

    ubuntu 安装vscode之后点击生成的图标无法打开 xff08 没有图标记得重启 xff09 xff0c 建议在安装地址直接打开可以看到报错信息 如果是root用户 xff0c 可能需要 no sandbox参数才能启动 继续执行 c
  • matlab的帮助文档切换成中文(求助贴)

    Matlab的帮助文档切换成中文 xff08 求助贴 xff09 题主的matlab版本 xff1a 2018a 系统win10 问题描述 xff1a 当使用matlab时 xff0c 有时需要使用help 语句查看一些关键字的用法 xff
  • Android使用Google Breakpad进行崩溃日志管理

    开发过程中 xff0c 最担心的问题就是程序崩溃 xff0c 而且还不知道崩溃的原因 xff0c 现在使用Google Breakpad来跟踪崩溃的位置 xff0c 非常方便 xff1b 由于目前使用Mac系统开发 xff0c Google
  • Python--使用jieba进行分词并计算词权重

    span class token keyword import span jieba span class token keyword import span xlrd span class token keyword import spa