LearnPythonforResearch
This repository provides everything you need to get started with Python for (social science) research.
Install / Use
/learn @TiesdeKok/LearnPythonforResearchREADME
Table of contents
- Introduction
- Getting your Python setup ready
- Using Python
- Tutorial Notebooks
- Code along
- Questions?
- License
- Special thanks
The goal of this GitHub page is to provide you with everything you need to get started with Python for actual research projects.
<h3 id="audience">Who is this repository for?</h3>The topics and techniques demonstrated in this repository are primarily oriented towards empirical research projects in fields such as Accounting, Finance, Marketing, Political Science, and other Social Sciences.
However, many of the basics are also perfectly applicable if you are looking to use Python for any other type of Data Science!
<h3 id="howtouse">How to use this repository?</h3>This repository is written to facilitate learning by doing
If you are starting from scratch I recommend the following:
- Familiarize yourself with the
Getting your Python setup readyandUsing Pythonsections below - Check the
Code along!section to make sure that you can interactively use the Jupyter Notebooks - Work through the
0_python_basics.ipynbnotebook and try to get a basics grasp on the Python syntax - Do the "Basic Python tasks" part of the
exercises.ipynbnotebook - Work through the
1_opening_files.ipynb,2_handling_data.ipynb, and3_visualizing_data.ipynbnotebooks.
Note: the2_handling_data.ipynbnotebook is very comprehensive, feel free to skip the more advanced parts at first. - Do the "Data handling tasks (+ some plotting)" part of the
exercises.ipynbnotebook
If you are interested in web-scraping:
- Work through the
4_web_scraping.ipynbnotebook - Do the "Web scraping" part of the
exercises.ipynbnotebook
If you are interested in Natural Language Processing with Python:
- Take a look at my Python NLP tutorial repository + notebook
If you are already familiar with the Python basics:
Use the notebooks provided in this repository selectively depending on the types of problems that you try to solve with Python.
Everything in the notebooks is purposely sectioned by the task description. So if you, for example, are looking to merge two Pandas dataframes together, you can use the Combining dataframes section of the 2_handling_data.ipynb notebook as a starting point.
There are multiple ways to get your Python environment set up. To keep things simple I will only provide you with what I believe to be the best and easiest way to get started: the Anaconda distribution + a conda environment.
<h3 id="anaconda">Anaconda Distribution</h3>The Anaconda Distribution bundles Python with a large collection of Python packages from the (data) science Python eco-system.
By installing the Anaconda Distribution you essentially obtain everything you need to get started with Python for Research!
<h4 id="anacondainstall">Step 1: Install Anaconda</h4>- Go to anaconda.com/download/
- Download the Python 3.x version installer
- Install Anaconda.
- It is worth to take note of the installation directory in case you ever need to find it again.
- Check if the installation works by launching a command prompt (terminal) and type
python, it should say Anaconda at the top.- On Windows I recommend using the
Anaconda Prompt
- On Windows I recommend using the
Note: Anaconda also comes with the Anaconda Explorer, I haven't personally used it yet but it might be convenient.
- Make sure you've cloned/downloaded this repository: Clone repository
cd(i.e. Change) to the folder where you extracted the ZIP file
for example:cd "C:\Files\Work\Project_1"
Note: if you are changing do folder on another drive you might have to also switch drives by typing, for example,E:- Run the following command
conda env create -f environment.yml - Activate the environment with:
conda activate LearnPythonforResearch
A full list of all the packages used is provided in the environment.yml file.
Python 3.x is the newer and superior version over Python 2.7 so I strongly recommend to use Python 3.x whenever possible. There is no reason to use Python 2.7, unless you are forced to work with old Python 2.7 code.
<h2 id="usingpython">Using Python</h2>Basic methods:
The native way to run Python code is by saving the code to a file with the ".py" extension and executing it from the console / terminal:
python code.py
Alternatively, you can run some quick code by starting a python or ipython interactive console by typing either python or ipython in your console / terminal.
The above is, however, not very convenient for research purposes as we desire easy interactivity and good documentation options.
Fortunately, the awesome Jupyter Notebooks provide a great alternative way of using Python for research purposes.
Jupyter comes pre-installed with the Anaconda distribution so you should have everything already installed and ready to go.
Note on Jupyter Lab
JupyterLab 1.0: Jupyter’s Next-Generation Notebook Interface
JupyterLab is a web-based interactive development environment for Jupyter notebooks, code, and data. JupyterLab is flexible: configure and arrange the user interface to support a wide range of workflows in data science, scientific computing, and machine learning. JupyterLab is extensible and modular: write plugins that add new components and integrate with existing ones.
Jupyter Lab is an additional interface layer that extends the functionality of Jupyter Notebooks which are the primary way you interact with Python code.
What is the Jupyter Notebook?
From the Jupyter website:
The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
In other words, the Jupyter Notebook allows you to program Python code straight from your browser!
How does the Jupyter Notebook/Lab work in the background?
The diagram below sums up the basics components of Jupyter:
<img src="https://i.imgur.com/1zFzbyw.png" title="Jupyter Notebook" width = 400px/>At the heart there is the Jupyter Server that handles everything, the Jupyter Notebook which is accessed and used through your browser, and the kernel that executes the code. We will be focusing on the natively included Python Kernel but Jupyter is language agnostic so you can also use it with other languages/software such as 'R'.
It is worth noting that in most cases you will be running the Jupyter Server on your own computer and will connect to it locally in your browser (i.e. you don't need to be connected to the internet). However, it is also possible to run the Jupyter Server on a different computer, for example a high performance computation server in the cloud, and connect to it over the internet.
How to start a Jupyter Notebook/Lab?
The primary method that I would recommend to start a Jupyter Notebook/Lab is to use the command line (terminal) directly:
- Open your command prompt / terminal (on Windows I recommend the Anaconda Prompt)
- Activate the right environment with
conda activate LearnPythonForResearch cd(i.e. Change) to the desired starting directory
for example:cd "C:\Files\Work\Project_1"
Note: if you are changing do folder on another drive you might have to also switch drives by typing, for example,E:- Start the Jupyter Notebook/Lab server by typing:
jupyter notebookorjupyter lab
This should automatically open up the corresponding Jupyter Notebook/Lab in your default browser.
You can also manually go to the Jupyter Notebook/Lab by going to localhost:8888 with your browser. (You might be asked for a password, which can find in the terminal window where there Jupyter server is running.)
***How to cl
Related Skills
claude-opus-4-5-migration
99.2kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
344.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
feishu-drive
344.4k|
things-mac
344.4kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
