唐诗宋词鉴赏-2

第二篇  道引曲--龚自珍

 

无情绪 ,无情绪。寂寞掩重门。

银蜡心多才有泪,宝香字断更无痕,梨花浸黄昏。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
下面是一个使用Python爬虫和文本处理库jieba实现的唐诗宋词经典案例: 1. 爬取唐诗宋词文本数据 ```python import requests # 爬取唐诗文本 def crawl_tang_poetry(): url = 'https://raw.githubusercontent.com/Werneror/Poetry/master/poetry_tang.txt' response = requests.get(url) text = response.text return text # 爬取宋词文本 def crawl_song_ci(): url = 'https://raw.githubusercontent.com/Werneror/Poetry/master/poetry_song.txt' response = requests.get(url) text = response.text return text ``` 2. 分词并统计词频 ```python import jieba from collections import Counter # 分词并统计词频 def word_count(text): words = jieba.cut(text) counter = Counter(words) return counter # 统计唐诗词频 tang_poetry = crawl_tang_poetry() tang_counter = word_count(tang_poetry) # 统计宋词词频 song_ci = crawl_song_ci() song_counter = word_count(song_ci) ``` 3. 生成词云图 ```python from wordcloud import WordCloud import matplotlib.pyplot as plt # 生成唐诗词云图 tang_wordcloud = WordCloud(width=800, height=600, background_color='white', font_path='msyh.ttc').generate_from_frequencies(tang_counter) plt.imshow(tang_wordcloud) plt.axis('off') plt.show() # 生成宋词词云图 song_wordcloud = WordCloud(width=800, height=600, background_color='white', font_path='msyh.ttc').generate_from_frequencies(song_counter) plt.imshow(song_wordcloud) plt.axis('off') plt.show() ``` 通过以上三步,我们就可以得到唐诗宋词的词云图了。这个案例可以帮助我们学习Python爬虫、文本处理和数据可视化的基础知识。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值