本文最后更新于 2025-12-17,文章内容可能已经过时。

初次使用jupyter notebook

import jieba.posseg as posseg
import pandas as pd
if __name__ == '__main__':
    with open('./半笙食谱.txt','r',encoding='utf-8') as fin:
        content  = fin.read()
    words = []
    for word,flag in posseg.cut(content):
        if flag == 'nr':
            words.append(word)
    result = str(pd.Series(words).value_counts()[:50])
    print(result[:-13:],end='')
管半笙    2087
钟谷     1107
叶一提     675
艾达      270
王轩      119
丛       111
周        84
张琪琼      76
叶一       71
钟        70
陈        69
神阙       69
师姐       62
阙        56
米其林      45
大师傅      40
明白       33
玄鸟       32
马大姐      29
小杨       27
明星       27
师傅       24
西红柿      22
段时间      17
连        16
小姐       16
山海经      12
陈老师      11
泰迪       11
林斐       10
檀香       10
小姑娘      10
阿姨        9
赵姐        8
安静        8
安全带       7
杜衡        7
钟谷刚       7
顾问        7
张哥        7
常客        7
别提        7
毛         7
郭         6
寻思        6
乌龟        6
周晓祥       6
和神阙       6
钟谷正       6
盏灯        5

第一次执行代码报错,原因未导入’jieba’库,导入后运行正常。

!pip install jieba
Collecting jieba
  Downloading jieba-0.42.1.tar.gz (19.2 MB)
     |████████████████████████████████| 19.2 MB 51.3 MB/s eta 0:00:01
[?25hBuilding wheels for collected packages: jieba
  Building wheel for jieba (setup.py) ... [?25ldone
[?25h  Created wheel for jieba: filename=jieba-0.42.1-py3-none-any.whl size=19314478 sha256=79727dcef27f501234de42d205f0850badeedf7c067f2650f25eee60e37b26c1
  Stored in directory: /root/.cache/pip/wheels/7d/74/cf/08c94db4b784e2c1ef675a600b7b5b281fd25240dcb954ee7e
Successfully built jieba
Installing collected packages: jieba
Successfully installed jieba-0.42.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv