Chapter 1 Welcome

G’day and welcome to Python cookbook for the casual dabbler.

Some history: I use the R language a lot for work and for side projects. However I’ll be the first to admit - for some things, python is simply much better.

Rather than storing my bits and bobs of python code in random files and repos, I’ve created this book to systematize key the key processes I use often, in one convenient location.

1.1 Using this book

In each chapter I’ve written up the background, methodology and code for a separate piece of analysis.

Most of this code will not be extraordinary to the seasoned Python aficionado. The vast majority can be found elsewhere if you dig around on stackexchange or read some of the many python programming blogs and books.

However I find that in classic Pareto style ~20% of my code contributes to the vast majority of my work output. Having this on hand will hopefully be useful to both myself and others.

1.2 Additional resources

The Python community is continually writing new books and package documentation with great worked examples. Some of my favourites are:

1.3 Limitations

I’ll be honest with you - there’s bound to be bugs galore in this. If you find one (along with spelling errors etc) please email me at charlesfcoverdale@gmail.com with the subject line ‘Python Cookbook for the Casual Dabbler.’

1.4 Why write a python book using the R publishing language?

It’s a fair question. The simplest answer is that the R Markdown and Bookdown languages are excellent - and far more conducive to longer form content compared to jupyter notebooks.

There are some quirks however. For example, to get python to run within the RStudio IDE I need to load up each chapter with some code (written in R) that looks something like this:

library(reticulate)

use_condaenv("tf")

reticulate::py_install("numpy")

reticulate::py_install("geopy")

Interested in publishing your own book using R Markdown or Bookdown? There’s some excellent books on the topic, however I find this guide as by far the most useful.


1.5 About the author

Charles Coverdale is an economist based in Melbourne, Australia. He is passionate about economics, climate science, and building talented teams. You can get in touch with Charles on twitter to hear more about his current projects.