Intro to Python

(for social scientists)

by Katharina Roesler, katroesler@gmail.com

Agenda

  1. Why learn Python?
  2. Installation
  3. Python Basics
  4. Exercises
  5. Scraping!
  6. Resources

Why learn Python?

  1. Free data!
  2. Fast, doesn’t crash
  3. Clean code, functions
  4. Existing libraries
  5. Lots of documentation and online help

Installation

  1. Python
  2. Python 2.7 vs. 3 (big debate)
  3. Homebrew for installing software
  4. Pip, easy_install
  5. Anaconda (optional)
  6. Sublime Text or Atom text editors
  7. Vim or Emacs (optional)
  8. Bash/shell commands (optional)

Exercises


All exercises and solutions are here.

An online Python interpreter is here.

Scraping!


Code for scraping CNN and Fox news is here.

Results are in the slides below, and all files are here.

CNN

Fox

Topic 1

Topic 5

Tips

  1. Write lots of comments
  2. Print output
  3. Small samples:
  4. Google every issue
  5. Activity Monitor
  6. caffeinate -w pid
  7. sudo

References

  1. Code Academy
  2. Nice Intro
  3. Jupyter Notebooks
  4. Topic Modeling in R
  5. Webscraper Extension in Chrome
  6. Dive Into Python Book

Questions? Comments?

katroesler@gmail.com