Taylor-Swift_DataScience_F_TS_casestudy_Thumbnail

How To Analyze Taylor Swift Lyrics & Find “Midnights” Clues Using Machine Learning

10/21/2022
5 minutes

Midnight on October 21, 2022 was either just another hour of your life, or an incredibly significant moment that you’d been counting down to for months, maybe even years. ICYMI, Taylor Swift dropped a new album, called Midnights, at midnight on the 21st.

Leading up to the release, eagle-eyed Swifties have been clocking the tiniest details — the way Taylor styles her hair, the number of words in an Instagram caption, the color of a phone in a split-second clip — and using them to craft convincing theories about the upcoming music.

The citizen detectives of #Swifttok know all too well that there’s meaning behind every little thing that Taylor does or says — and we can use data science to uncover deeper meaning behind her words.

Learn something new for free

Data science is a combination of probability, statistics, software engineering, and business knowledge. A Data Scientist is someone who takes large amounts of information and translates it into something actionable. Using programming languages and other coding tools, Data Scientists can meticulously analyze huge amounts of data and find trends and patterns that humans would miss.

So what’s this got to do with a mega pop star’s music? Well, we know that Taylor intentionally plants Easter eggs about new music years in advance for fans to find.

Taylor described this new album Midnights as “the stories of 13 sleepless nights scattered throughout my life.” One major Midnights clue was that Taylor had sung about “midnight” and “middle of the night” in the lyrics of lots of her songs. When you think about her 18-year music career, there’s a lot of data that could be sprinkled with surprises.  

In the new Codecademy case study Analyze Taylor Swift Lyrics with Python, you’ll get to analyze the lyrics of every song in Taylor’s discography leading up to Midnights to look for clues. You’ll use Python and Jupyter Notebooks to take a deep dive into her robust catalog of music, and conduct natural language processing (NLP), a machine learning technique that enables you to process verbal and written language using artificial intelligence, to scour her lyrics.

Using code, you’ll make data visualizations like line charts, rug plots, wordclouds, and pie charts with your findings. Here’s an example of a line chart you’ll make that looks at “night” mentions in lyrics over time:

Taylor’s mentions of “night” words starkly decline in the three years preceding this album release. If the common Swiftie theory is true — that Taylor plans three years in advance — it seems like she was gearing up for a big “night” moment in the years leading up to the “Midnights” release.

Curious if Taylor Swift songs mention “night” more than “day”? Look at this graph:

Taylor has said that the 2019 album “Lover” was almost titled “Daylight.” As you can see, she mentions “day” in her lyrics far more than “night.”

And using sentiment analysis, we can see whether her lyrics tend to be positive or negative. This chart looks at positive sentiment over time:

You’ll notice a big dip in positive sentiment around 2020, which was her “folklore” era.

In this case study, you’ll turn to data to answer other pressing questions like:

  • Do Taylor’s albums follow a pattern of mentioning midnight?
  • Do the songs that mention “nights” in the lyrics have a positive or negative sentiment?
  • What words, overall, does Taylor use the most in her song lyrics?
Watch Codecademy’s Data Domain Manager Michelle McSweeney walk through this case study.

Before you jump in, you’ll need to have a grasp on Python and NLP. Check out the path Apply Natural Language Processing with Python to learn about the exciting field that combines linguistics, AI, and computer science.

Want to take your TSwift fandom to the next level, but don’t know how to code yet? This is a fun excuse to learn (or begin again)! You can start with any of our Code Foundations courses to get introduced to programming concepts that lay the groundwork for more advanced skills. We also have lots of beginner-friendly data science courses that you can take for free, plus a guide that helps you choose a data science language to learn first. If you’re ready to start learning Python, consider taking our popular course Learn Python 3.

You might be learning these techniques to participate in the Midnights mayhem, but coding skills can help your career and life for evermore. (Just ask Taylor’s erstwhile bestie, Karlie Kloss.)

If it’s in your wildest dreams to have a career as a Data Scientist, we can help you get there. The path Data Science Foundations will teach you how to clean and analyze data, and get you ready for a career in data science. Or you could take the Career Path Data Scientist: Natural Language Processing Specialist to learn how to think about, visualize, and analyze data and get started with AI.

The new Codecademy case study Analyze Taylor Swift Lyrics with Python is just one example of how data science can be applied to our interests and daily lives. For more real-world practice using data to forecast outcomes, check out our Practice Projects in Python. If you tuned into the NFL on Thursday night to catch the Midnights Teaser trailer, you might also want to try our case study Analyze NFL Stats with Python — you’ll build a machine learning model that predicts the winners of NFL games.

Throughout your coding journey, remember that you’re not on your own, kid: You can connect with other people who are learning to code on Codecademy’s forums, or join a local Codecademy chapter.  

It feels like a perfect night for coding at midnight. Ready to get started? Check out Analyze Taylor Swift Lyrics with Python.

Related courses

3 courses

Related articles

7 articles
what-is-python-used-for.png?w=1024

What Is Python Used For?

07/26/2024
7 minutes
By Stephan Miller

Python’s versatility makes it a valuable addition to any developer’s tech stack. Here, we explore its advantages and applications in different industries.