Importing transcript data

A curated data frame of metadata and text variables derived from episode and movie transcripts can be downloaded with st_transcripts. The format is one episode per row. There are metadata columns and a list column of nested text variables.


(scriptData <- st_transcripts())
#> # A tibble: 726 x 10
#>    format  series season number title   production airdate  url     url2   text 
#>    <chr>   <chr>   <int>  <int> <chr>        <int> <chr>    <chr>   <chr>  <lis>
#>  1 episode TOS         1      0 The Ca~          1 <NA>     https:~ http:~ <tib~
#>  2 episode TOS         1      1 The Ma~          6 1966-09~ https:~ http:~ <tib~
#>  3 episode TOS         1      2 Charli~          8 1966-09~ https:~ http:~ <tib~
#>  4 episode TOS         1      3 Where ~          2 1966-09~ https:~ http:~ <tib~
#>  5 episode TOS         1      4 The Na~          7 1966-09~ https:~ http:~ <tib~
#>  6 episode TOS         1      5 The En~          5 1966-10~ https:~ http:~ <tib~
#>  7 episode TOS         1      6 Mudd's~          4 1966-10~ https:~ http:~ <tib~
#>  8 episode TOS         1      7 What a~         10 1966-10~ https:~ http:~ <tib~
#>  9 episode TOS         1      8 Miri            12 1966-10~ https:~ http:~ <tib~
#> 10 episode TOS         1      9 Dagger~         11 1966-11~ https:~ http:~ <tib~
#> # ... with 716 more rows

#> # A tibble: 816 x 6
#>    line_number perspective    setting         description character line        
#>          <int> <chr>          <chr>           <chr>       <chr>     <chr>       
#>  1          NA <NA>           "Fade in"       <NA>        <NA>      <NA>        
#>  2           1 Ext. Space - ~ "The u.s.s. En~ <NA>        Picard V~ Captain's l~
#>  3           2 Other introdu~ "On the gigant~ <NA>        Picard V~ My orders a~
#>  4           3 Int. Engine r~ "Huge, with a ~ Continuing  Picard V~ ... I am be~
#>  5           4 Closer on ves~ "Showing the d~ <NA>        Picard V~ I am still ~
#>  6          NA Int. Lounge d~ "With its huge~ <NA>        <NA>      <NA>        
#>  7           5 Continued       <NA>           Continuing  Picard V~ ... my crew~
#>  8           6 Int. Bridge -~ "Picard, troi,~ Continuing  Picard V~ ... a first~
#>  9           7 Angle emphasi~ "As picard tur~ <NA>        Picard    You will ag~
#> 10           8 Angle emphasi~  <NA>           <NA>        Data      Difficult .~
#> # ... with 806 more rows

Basic TNG summary

Consider TNG episodes. A rough estimate of the relative amount of speaking parts can be obtained by counting up the lines for each character. A better measure would be an estimate of word count taken from each spoken line. Calculate these statistics by season and episode as well as character.

Also remove unneeded columns. As is common in text analysis, even a clean dataset may need further preparation for a specific task. In this case it is important to strip references to things such as voice over (V.o.) from the character column.

Another limitation of using lines is that they may not always mimic the natural breaks in spoken lines in the episodes. While word count here is simply estimated by breaking text on spaces, it is likely more representative than the line count.

Total spoken words

Next, focus on the top eight characters.

By the way, look at the total estimated lines and words spoken by each character. These are of course rough estimates. Nevertheless, it is interesting to see that Picard has nearly twice as much to say as the next most talkative character on the show, the Android, Data. It must be all those impromptu diplomatic speeches.

Transferring from TNG to DS9

Finally, look at both Worf and O’Brien, making a comparison between TNG and DS9 in terms of their prominence.

This is a simple exploration of the data, but the results are interesting. Starfleet promotions in rank aside, Worf did not even quite receive a 10% pay bump in terms of average spoken words per episode. On the other hand, O’Brien had an increase of 211%, or more than triple the average number of spoken words per episode when moving from the Enterprise to Deep Space Nine. All things considered, take the transfer. But on spoken words alone, O’Brien was clearly favored. The squeaky wheel gets the grease.


This calculation accounts for the number of episodes each character has speaking lines in. For example, TNG episodes missing O’Brien after DS9 began and DS9 episodes missing Worf before he joined the show are not counted against them.

It does not account for episodes where a character may appear in an episode, but without any speaking lines, which should drop their averages. However, this is rare and, if anything, I would expect it to exacerbate the difference seen here rather than diminish it. I’m just guessing there may have been some early TNG episodes where O’Brien was shown but never spoke.

A more rigorous approach that I may show in a subsequent example would be to join this transcript data with episode casting data from STAPI so that there is no need to rely on speaking lines in transcripts to guess at whether someone was featured in an episode.