Python Modules You Didn’t Know You Needed

One of the things that happens as you nurture and grow a software stack is that you begin to take its functionality for granted, and, when you are faced with the prospect of re-creating it elsewhere or over, you realize you need better documentation. My work is currently founded on Python, and I have already documented the great architecture that is numpy + scipy + nltk + pandas + matplotlib + … you get the idea.

  • jupyter is central to how I work my way through code, and when I need to present that code, I am delighted that jupyter gives me the option to present a notebook as a collection of slides. RISE makes those notebooks fly using Reveal.js.
  • missingno “provides a small toolset of flexible and easy-to-use missing data visualizations and utilities that allows you to get a quick visual summary of the completeness (or lack thereof) of your dataset. It’s built using matplotlib, so it’s fast, and takes any pandas DataFrame input that you throw at it, so it’s flexible. Just pip install missingno to get started.”

I’ve got more … I just need to list them out.

Append a Python List Using a List Comprehension

In some code with which I am working at the moment, I need to be able to generate a list of labels based on a variable number that I provide elsewhere in a script. In this case, I am working with the Sci-Kit Learn’s topic modeling functions, and as I work iteratively through a given corpus, I am regularly adjusting the number of topics I think “fit” the corpus. Elsewhere in the script, I am using pandas to create a dataframe that contains the names of the texts as row labels and then the topic numbers will be used as column labels.

df_lda_DTM = pd.DataFrame(data= lda_W, index = docs, columns = topic_labels)

In the script, I simply use n_components to specify the number of topics which which the function, LDA or NMF, is to work.

I needed some way to generate the topic labels on the fly so that I would not be stuck with manually editing this:

topic_labels = ["Topic 0", "Topic 1", "Topic 2"]

I was able to do so with a for loop that looked like this:

topic_labels = []
for i in range(0, n_components):
    instance = "Topic {}".format(i)
    topic_labels.append(instance)

Eventually, it dawned on me that range only needs the upper bound, so I could drop the 0 inside the parenthesis:

topic_labels = []
for i in range(n_components):
    topic_labels.append("Topic {}".format(i))

That works just fine, but, while not a big block of code, this piece is part of a much longer script, and if I could get it down to a single line, using a list comprehension, I would make the overall script much easier to read, since this is just a passing bit of code that does one very small thing. One line should be enough.

Enter Python’s list comprehension, a bit of syntax sugar, as pythonistas like to call it, that I have by no means, er, fully comprehended. Still, here’s an opportunity to learn a little bit more.

So, following the guidelines for how you re-block your code within a list comprehension, I tried this:

topic_labels = [topic_labels.append("Topic {}".format(i)) for i in range(n_components)]

Better coders than I will recognize that this will not work, and will return a list of [None, None, None].

But appending a list is simply one way of building a list, of adding elements to a list, isn’t it? I could use Python’s string addition to pull this off, couldn’t I? Yes, yes I could, and did:

topic_labels = ["Topic " + str(i) for i in range(n_components)]

It couldn’t be simpler, and shorter. And it works:

print(topic_labels)
['Topic 0', 'Topic 1', 'Topic 2']

Readings in the Digital Humanities

Occasionally, a colleague or student wants to learn more about the digital humanities. Here is a list of texts/sites/journals that are worth their consideration.

Texts/Sites

Literary Studies in the Digital Age: An Evolving Anthology is “published by the Modern Language Association of America. It is the MLAs first born-digital, publicly available anthology. It launched in 2013 and continues to grow. The editors welcome new submissions that will expand the breadth and depth of the collection, including pieces that offer primers on topics, tools, and techniques pertinent to computational approaches in literary studies as well as essays that deepen or nuance topics already covered in the volume.” Some of these essays are the de facto standard introductions to various dimensions of the digital humanities. They aren’t necessarily my favorites or even the best, but they do fall under the category of “everyone at least claims to have read them.”

Digital Humanities Spotlight: 7 Important Digitization Projects includes Mapping the Republic of Letters, London Lives, Charles Darwins Library, the Salem Witch Trials Documentary Archive and Transcription Project, The Newton Project, and Quijote Interactivo. This is an interesting collection of some of the more polished sites that are also publicly accessible.

Journals

DHQ: _Digital Humanities Quarterly.

DSH Digital Scholarship in the Humanities — the journal formerly known as LLC, _Literary and Linguistic Computing.

JDH: Journal of Digital Humanities.

And maybe:

CA: Journal of Cultural Analytics.

ISCLR 2017 Conference Schedule

This is not an official version of the schedule. Simply a readily available one so that fellow folklorists can see who presented what at this year’s meeting.

JUNE 6

Supernatural Legends and Place

  • Constraints of Ghost Walks and Haunted Tourism in Utah • Kylie Schroeder
  • Mysterious Northeast Arkansas: Ghost Stories in Jonesboro • Richard Burns
  • Supernatural Creatures and Belief in South Louisiana • Carolyn E. Ware

Hauntings

  • The Mad Doctor of the Pennhurst Haunted Asylum • Shannon K. Larson
  • The Haunted Cheerio and Other Tales: Negotiating Belief in a Louisiana Classroom • Shelley Ingram

JUNE 7

Local Legendry

  • Hidden Treasures in Welsh Legendry • Elissa R. Henken
  • Jean Lafitte and the Other Lex Non Scripta: Outlaw as Expression of Folk Law • Keagan LeJeune
  • The Peck Ranch Massacre and Formulaic Atrocity • William M. Clements

Legend and Media I

  • Slenderman is Coming to Get Your Little Brother or Sister: Teenagers’ Legend-Related Pranks on You-Tube • Libby Tucker
  • The One at the Conference: Podcasting and Legend Scholarship • Eleanor Hasken

Legend and Media II

  • The Myth of the “Killer 2026”: Serial Killer, Urban Legend, or Both? • Daniel P. Compora
  • Framing Children’s Narratives in Online Clown Legends • Jessica Doble
  • The Clown Legend Cascade: The Legend Conduit in the Information Age • John Laudun

JUNE 8

Fake News I

  • Pizzagate, Fake News and Its Ostensive Consequences • Jesse Fivecoate
  • Crawford Road: Legend, News, and Stigmatized Places • Kristina Downs

Fake News II

  • Fake News, Folk News, and Contemporary Legends: Information and Belief in the Age of #Alternative Facts • Andrea Kitta & Lynne McNeill

Fake News, Folk News

  • Fake News, ‘Folk News’ and the Fate of the Far Away Moses • Steven Winick
  • Conspiracy, Legendry, and the Politics of Culture in the Case of the
  • Jonesboro Property Maintenance Code • Gregory Hansen
  • Cuckolding and Consent: An Analysis of Power and Sex within the Alt-Right • Bakr Abbahou

JUNE 9

Narrative Motifs

  • Ambrož Kvartič, Shibboleth: A Mechanism of Language Differentiation as a Narrative Folklore Motif
  • Contemporary Legend and Rumor: A Response to Dr. Hobbs • David Samper