Introduction to Python

Dr. W.J.B. Mattingly
Smithsonian Data Science Lab and United States Holocaust Memorial Museum
January 2022

Covered in this Chapter

  1. Why should humanists learn to code?

  2. Why use Python specifically?

  3. What is covered in this textbook?

  4. How to Use Python from this Textbook

  5. How to Use Python on JupyterOrg

  6. How to Install Python with Anaconda Navigator and Jupyter-Lab

About the Author

I am Dr. William Mattingly. I hold a PhD in Medieval History from the University of Kentucky where I explored early medieval social networks. A lot of my research was aided by my ability to code, specifically in Python, for data cleaning and analysis. Currently, I am a Postdoctoral Fellow for the Analysis of Historical Documents at the Smithsonian Institution’s Data Science Lab with a joint appointment at the United States Holocaust Memorial Museum. In both institutions, I use Python, machine learning, and natural language processing (NLP) to analyze historical texts in large quantities to generate new insights about the documents held in the archives. In all, I have nearly a decade of experience using Python as a historian.

When I first started to explore Python, there were not many available tutorials geared towards humanists and, for that reason, four years ago I started PythonHumanities.com and Python Tutorials for Digital Humanities on YouTube. I structured these resources to humanists who had no prior knowledge about computing or coding. This new JupyterBook is the third iteration of this textbook that brings a lot of the material that first appeared on PythonHumanities.com years ago into a new, more accessible JupyterBook. It will forever remain free to all as will the video lectures embedded in each chapter.

About this Textbook

If you are reading this textbook, then you are probably a humanist interested in coding. If you are here, then it is likely true that you have already been presented with or heard about the benefits of learning to program. Nevertheless, I will begin this textbook with the presumption that you need convincing. It is my hope that by the end of this chapter, you will not only have a clear understanding of the utility of coding, but its direct applications to humanities-based inquiry. You will also learn about Python specifically and where it sits within the realm of coding languages. This chapter will not argue that Python is the best programming language, rather it will present the strengths and weaknesses of it compared to others available. I will conclude this chapter with a brief outline of this textbook, so that you will have a clear picture of where we are going and, most importantly, why.

If you have no coding experience, please do not worry. I presume no knowledge on the part of the reader about computers or programming. This textbook is meant to serve both as a primary and a refresher. As you progress through this textbook, you will notice video links. These videos are meant to serve as video-based lectures that cover the material in greater detail. While text is a well-suited medium for educating others, with programming it is sometimes important to watch live coding. More importantly, a person learning to code should engage with the language itself.

This particular textbook is coded in JupyterBook. A good way to think about JupyterBook is as a regular electronic textbook that allows me, the author, to execute code so that you, the reader, can see the results. It also allows you, the reader, to download the book and execute the commands locally. I will be explaining all of this as we progress through the textbook.

At the end of many chapters, there will be a quiz. These are designed to help you reinforce the key concepts that you have learned.

Because this textbook is not peer-reviewed, typos may remain or errors may exist. I openly and freely admit to this. This textbook is community-inspired and I would like it to be community-supported. If you see a mistake, you can click thee GitHub logo inn the top right corner of the screen to submit a pull request or make a note for edits. I highly encourage this and I am open to and welcome any criticism to improve this textbook for all.