B2022 - PYTHON FOR ECONOMISTS

Academic Year 2024/2025

  • Docente: Pietro Rossi
  • Credits: 6
  • SSD: SECS-P/01
  • Language: English
  • Teaching Mode: Traditional lectures
  • Campus: Bologna
  • Corso: Second cycle degree programme (LM) in Economics and Public Policy (cod. 5945)

    Also valid for Second cycle degree programme (LM) in Applied Economics and Markets (cod. 5969)

Learning outcomes

This course provides theory and tools for using Python as a programming language in economic research. It (i) introduces students to the basic logic and syntax of Python (e.g. object-oriented programming) and (ii) emphasizes how to use it to perform Data Science-related tasks (working with relational dataset, big data, data visualization, among others).

Course contents

Basic Python

  1. Using the Python Interpreter
  2. An Informal Introduction to Python
  3. Control Flow Tools
  4. Data Structures
  5. Modules
  6. Input and Output
  7. Errors and Exceptions
  8. Classes
  9. Brief Tour of the Standard Library
  10. Virtual Environments and Packages

NumPy

  1. Array objects
    The N-dimensional array (ndarray)
    Scalars
    Data type objects (dtype)
    Indexing routines
    Iterating Over Arrays
    Standard array subclasses
    Masked arrays
    The array interface protocol
    Datetimes and Timedeltas
  1. Constants
  2. Routines
    Array creation routines
    Array manipulation routines
    Binary operations
    String operations
    Mathematical functions with automatic domain
    Floating point error handling
    Functional programming
    NumPy-specific help functions
    Input and output
    Linear algebra (numpy.linalg)
    Logic functions
    Masked array operations
    Mathematical functions
    Miscellaneous routines
    Random sampling (numpy.random)
    Set routines
    Sorting, searching, and counting
    Statistics

SciPy

Introduction
Special functions (scipy.special)
Integration (scipy.integrate)
Optimization (scipy.optimize)
Interpolation (scipy.interpolate)
Linear Algebra (scipy.linalg)
Statistics (scipy.stats)


pandas

  1. basics
    Object creation
    Viewing data
    Selection
    Missing data
    Operations
    Merge
    Grouping
    Reshaping
    Time series
    Categoricals
    Plotting
    Getting data in/out
    Gotchas
  2. Intro to data structures
  3. Essential basic functionality
  4. IO tools (text, CSV, HDF5, …)
  5. Indexing and selecting data
  6. MultiIndex / advanced indexing
  7. Merge, join, concatenate and compare
  8. Reshaping and pivot tables
  9. Working with text data
  10. Working with missing data
  11. Categorical data
  12. Computational tools
  13. Group by: split-apply-combine

Elements of matplotlib

Readings/Bibliography

https://docs.python.org/3/tutorial/

https://numpy.org/doc/stable/reference/index.html

https://docs.scipy.org/doc/scipy/tutorial/index.html

https://pandas.pydata.org/docs/getting_started/tutorials.html

https://matplotlib.org/stable/tutorials/introductory/index.html


Teaching methods

In presence.

Teacher explaining concepts and discussing exercises

Assessment methods

Through the course there will be 2 or 3 home assignment that students are expected to do and return to the tutor for grading.

Home assigned are tailored to occupy the student from 1 to 2 hours.

Final exam will be a written exam consisting in a challenging programming task.

Th final grade will be weighted equal between home assignment and the final exam.

Writing a computer program entails, among other three aspects I want to emphasize: correctness, clean programming style and performance. Correctness will absorb 60% of the value, coding style will weight 30%, the remaining 10% is taken up by performance

Teaching tools

Most will be frontal lectures were the teacher explains concepts and discusses examples.

Python code will be showcased both as standalone scripts, developed within an IDE but most of all examples will be presented via the Notebook.

The most important tool will be the large number of exercises that will be proposed and will challenge the student.



Office hours

See the website of Pietro Rossi