原文地址

Data Visualization and Analysis of Taylor Swift’s Song Lyrics

英语学习时间

Taylor Swift

- She is the youngest person to single-handedly write and perform a number-one song on the Hot Country Songs chart published by Billboard magazine in the United States.

- Apart from that she is also the recipient of 10 Grammys, one Emmy Award, 23 Billboard Music Awards, and 10 Country Music Association Awards.

- song lyrics 歌词

数据集

Taylor Swift 的 6 张专辑(album)96首歌的歌词

6列数据

- 歌手名 artist

- 专辑名 album name

- 歌名 track title

- 专辑中第几首歌 track number

- 歌词(每句一行)lyric

- 歌词是这首歌的第几句 line number

- 发表年份 year of release of the album

主要的分析内容

探索性数据分析 - 每首歌和每张专辑的歌词的单词数量 - 单词数量随着年份的变化 - 单词数量的频率分布

文本挖掘

  • 词云
  • bigram network (暂时还不太明白这个是什么意思)
  • 情感分析 (sentiment analysis)

使用的工具是R语言

探索性数据分析

接触到一个新的函数:stringr包中的str_count() 帮助文档中的例子

library(stringr)
fruit <- c("apple", "banana", "pear", "pineapple")
str_count(fruit, "a")
#输出结果是
[1] 1 3 1 1

作用是统计每个字符串中符合特定规则的字符的数量 比如

str_count("A B C","S+")

输出的是“A B C”字符串中非空字符的数量(S+是正则表达式的一种写法,自己还没有掌握) 读入数据

lyrics<-read.csv("taylor_swift_lyrics_1.csv",header=T)
head(lyrics)

计算每句歌词的长度

library(stringr)
lyrics$length<-str_count(lyrics$lyric,"S+")
head(lyrics)

计算每首歌的歌词长度

library(dplyr)
length_df<-lyrics%>%group_by(track_title)%>%summarise(length=sum(length))
head(length_df)
dim(length_df)

第一项内容:单词数量最多的10首歌

Top10wordCount<-arrange(length_df,desc(length))%>%slice(c(1:10))
library(ggplot2)
ggplot(Top10wordCount,aes(x=reorder(track_title,length),y=length))+geom_col(aes(fill=track_title))+coord_flip()+ylab("Word count") + xlab ("") + ggtitle("Top 10 songs in terms of word count") + theme_minimal()+theme(legend.position = "none")

从上图可以看到,单词数量最多的歌是 End Game 排名第二的是 Out of the Woods

第二项内容:单词数最少的10首歌

Top10wordCount<-arrange(length_df,length)%>%slice(c(1:10))
library(RColorBrewer)
color<-rainbow(10)
ggplot(Top10wordCount,aes(x=reorder(track_title,-length),y=length))+geom_col(aes(fill=track_title))+coord_flip()+ylab("Word count") + xlab ("") + ggtitle("Top 10 songs in terms of word count") + theme_minimal()+scale_fill_manual(values = color)+theme(legend.position = "none")+theme(legend.position = "none")

单词数量最少的歌是 Sad Beautiful Tragic,发布于2012年,是 Red 这张专辑中的歌

第三项内容:单词数量的频率分布

ggplot(length_df, aes(x=length)) + geom_histogram(bins=30,aes(fill = ..count..)) + geom_vline(aes(xintercept=mean(length)),color="#FFFFFF", linetype="dashed", size=1) +geom_density(aes(y=25 * ..count..),alpha=.2, fill="#1CCCC6") +ylab("Count") + xlab ("Legth") + ggtitle("Distribution of word count") + theme_minimal()

第四项内容:每张专辑的单词数量

lyrics %>% group_by(album,year) %>% summarise(length = sum(length))%>%na.omit()-> length_df_album
length_df_album
ggplot(length_df_album, aes(x= reorder(album,-length), y=length)) +geom_bar(stat='identity', fill="#1CCCC6") + ylab("Word count") + xlab ("Album") + ggtitle("Word count based on albums") + theme_minimal()

第五项内容:每张专辑单词数量随时间的变化趋势

length_df_album %>% arrange(desc(year)) %>% ggplot(., aes(x= factor(year), y=length, group = 1)) +geom_line(colour="#1CCCC6", size=1) + ylab("Word count") + xlab ("Year") + ggtitle("Word count change over the years") + theme_minimal()+geom_point(aes(x=factor(year),y=length,size=length,color=factor(year)),alpha=0.5)+scale_size_continuous(range=c(5,15))+theme(legend.position = "none")

第五项内容:词云图

library("tm")
library("wordcloud")
lyrics_text <- lyrics$lyric
lyrics_text<- gsub('[[:punct:]]+', '', lyrics_text)
lyrics_text<- gsub("([[:alpha:]])1+", "", lyrics_text)
docs <- Corpus(VectorSource(lyrics_text))
docs <- tm_map(docs, content_transformer(tolower))
docs <- tm_map(docs, removeWords, stopwords("english"))
tdm <- TermDocumentMatrix(docs)
m <- as.matrix(tdm)
word_freqs = sort(rowSums(m), decreasing=TRUE)
lyrics_wc_df <- data.frame(word=names(word_freqs), freq=word_freqs)
lyrics_wc_df <- lyrics_wc_df[1:300,]
set.seed(1234)
wordcloud(words = lyrics_wc_df$word, freq = lyrics_wc_df$freq,min.freq = 1,scale=c(1.8,.5),max.words=200, random.order=FALSE, rot.per=0.15,colors=brewer.pal(8, "Dark2"))

情感分析

剩下的部分有时间回来补上

欢迎大家关注我的公众号

小明的数据分析笔记本

文章中用到的数据大家可以自己在原文链接下载,也可以在我的公众号留言

invalid floating point operation什么意思_数据可视化有意思的小例子:Taylor Swift 歌词数据分析和可视化...相关推荐

  1. 【Python入门可视化】:22个完整数据可视化小例子,带你玩转可视化~

    总共22个完整的pyecharts例子,包含常用的配置方法,每个小例子都包含完整代码,为避免混淆,每个例子都差不多只包含单一配置的代码,更多有趣的源码分享可以在评论区回复. 1. 柱状图堆叠 不同系列 ...

  2. invalid floating point operation什么意思_Point-MVSNet:基于多视角的点云重建网络

    Point-Based Multi-View Stereo Network是一篇点云重建领域的文章,其工作内容为通过输入多张不同角度的图片,提取不同的点云特征,再进行融合,从而生成最终的点云. 1.介 ...

  3. 软考报名照片验证软件报错invalid floating point operation

    原因一:照片验证软件下载问题,请解压后再进行安装 原因二:考虑可能是照片的存储路径存在特殊符号问题,将源照片的路径更换至无特殊符号的存储路径下方可解决.

  4. 解决提示:Invalid floating point operation.无效的浮点运算

    一步就搞定,在该屏幕的FormCreate函数中加入这段代码:Set8087CW(DWord($133f)); 已经在Delphi7的程序中测试通过,如果在其他版本中不行,那请再找原因 交流QQ:26 ...

  5. java notify视频_一个很好的小例子来演示java中的wait()和notify()方法

    任何人都可以在 java中为我提供一个很好的小例子演示wait()和notify()功能.我尝试使用下面的代码,但它没有显示我的预期. public class WaitDemo { int i = ...

  6. mysql杨辉三角_两个经典的小例子:杨辉三角和水仙花

    package fllower; /** * 打印杨辉三角 * @author acer * */ public class YangHui { public static void main(Str ...

  7. 数据科学生命周期_数据科学项目生命周期第1部分

    数据科学生命周期 This is series of how to developed data science project. 这是如何开发数据科学项目的系列. This is part 1. 这 ...

  8. 机器学习结合大数据面试_数据科学面试机器学习

    机器学习结合大数据面试 总览 (Overview) This post will provide a technical guide on machine learning theory within ...

  9. python代码少儿编程转换_数据类型转换_清华尹成python入门教程_少儿编程视频-51CTO学院...

    此课程与<清华编程高手.尹成.带你实战python入门>大体相同,只需购买其中的一门课程. 本课程由清华大学尹成老师录制,课程的特色在于讲解原理的同时引入了每个程序员都热衷的黑客技术.py ...

最新文章

  1. java开怎么能不知道Netty几个核心类呢?
  2. SQL Server 2012 复制(发布订阅的研究)
  3. Openstack组件部署 — Nova_安装和配置Controller Node
  4. vue 跳转页面带对象_vue从一个页面跳转到另一个页面并携带参数
  5. 升级MariaDB为10.1版本
  6. 怎么从计算机上删除东西吗,怎么在电脑中删除不想要的软件
  7. CGLib动态代理原理及实现
  8. java xml 解析 列表_用Java解析高级XML
  9. mysql事务保证幂等_事务与一致性:刚性or柔性
  10. E-Prime软件包及安装
  11. hive窗口函数使用详解
  12. Mac 使用U盘重装系统
  13. win下使用curl
  14. 一:【博客分享】优秀的有趣的博客
  15. 什么是计算机?计算机的硬件系统组成有哪些?
  16. 设置Google文档离线同步,更好的高效离线工作
  17. Wildcard Matching 1
  18. ElasticSearch的常用查询语句
  19. ds18b20温度转换指令_DS18B20传感器温度转换指令( )。
  20. java文档注释用什么开头,极其重要

热门文章

  1. Linux的which查找环境变量的文件
  2. 车险赔付率分析报告_车险改革究竟是涨价还是降价了?9月19号后买会便宜吗?...
  3. PHP对象的内存模型
  4. @configurationproperties注解给属性赋值
  5. php如何定义和使用常量,如何在PHP中定义和使用常量
  6. java比较map_java-比较hashMap值
  7. 【阿里云OSS】403错误,AccessDenied:The bucket you access does not belong to you.
  8. Spring Cloud:多网卡问题
  9. 印钞机 java c c vb_自己动手写一个印钞机 第六章
  10. c# 再次尝试 连接失败_和平精英ios充值失败该怎么办