0
$\begingroup$

Inspired by topic modeling and clustering analysis of Taylor Swift's lyrics, I want to do the same for the band Nightwish. I scraped Dark Lyrics (see script) for all of their lyrics and saved the results into a single plain text file that looks like this:

enter image description here

To perform my intended analyses, I want the target file to look like this, where each row is a line of lyric with columns indicating the corresponding album (wrapped around by "*") and song (after a track number "n. ") titles.

enter image description here

Maybe I can just read each line as a row and manually add album and song titles. However, I was wondering if there's a more efficient way to do this.

$\endgroup$
  • 1
    $\begingroup$ It's not entirely clear what differentiates a song and album in your dataset. Is demo night wish the album? And is 1.Forever Moments and 2.Night Wish songs? You could easily extract the desired information If all of your data follows the pattern where the album is surrounded by stars "*" and the song are numbered. $\endgroup$ – nwaldo Apr 20 at 4:54
  • $\begingroup$ @nwaldo Sorry about the confusion and yes, album titles are wrapped around by "*" and song titles following a number. I'm thinking about reading the whole text file into a single column (each line is a row), using a dictionary to store the indices and the content of album/song titles, and creating new title columns based on that. Is this the simplest way to do this? Thanks! $\endgroup$ – ramund Apr 20 at 17:24
  • $\begingroup$ That's like a good strategy. Depending on the size of the file, I would recommend reading it into a list, then use regular expressions to identify the album or title, and then store it into a nested list. For example [['Album 1', 'Track 1'], ['Album 1', 'Track 2'], ['Album 1', 'Track 3'], ['Album 2', 'Track 1'] ..., ['Album 3', 'Track 5']]. You can then convert this list into a pandas data.frame. $\endgroup$ – nwaldo Apr 20 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.