pandas
Definition from the website
Everything we learned using pandas
Anatomy of a Pandas DataFrame
CSV file
pd.Series
Geom
Alg
Trig
Calc
| 4.0 |
| 4.3 |
| 2.0 |
| 2.3 |
Take one column
Take one row
| 1.3 |
| 4.0 |
| 1.3 |
Susie
Jay
Lara
pd.Series
A ✨fancy numpy array, but with an index column
Take one column
Susie
Jay
Lara
pd.DataFrame
✨ Fancy Google Sheets or Excel but in Python
| Trig | Alg | Geom | Calc |
|---|---|---|---|
| 1.3 | 1.3 | 3.7 | 2.3 |
| 4.0 | 4.3 | 2.0 | 2.3 |
| 1.3 | 1.0 | 2.0 | 3.0 |
Open with pandas
Index
| Name | Trig | Alg | Geom | Calc |
|---|---|---|---|---|
| Lara | 1.3 | 1.3 | 3.7 | 2.3 |
| Jay | 4.0 | 4.3 | 2.0 | 2.3 |
| Susie | 1.3 | 1.0 | 2.0 | 3.0 |
SQL and SQL Databases
SQL = Structured Query Language
What is it?
A programming language for managing data in a relational database.
Relational Databases
Tabular data stored in rows and columns
with
multiple interconnected tables
Susie
Jay
Lara
| Trig | Alg | Geom | Calc |
|---|---|---|---|
| 1.3 | 1.3 | 3.7 | 2.3 |
| 4.0 | 2.0 | 2.3 | |
| 1.3 | 1.0 | 3.0 |
Susie
Jay
Lara
| Last | Age | Uni | Cats |
|---|---|---|---|
| Jones | 22 | TUM | 0 |
| Sun | 23 | LMU | 6 |
| Blue | 25 | LMU | 1 |
Here they have the same Index
so we can take data from multiple tables
grades
students
Relational Databases
Susie
Jay
Lara
| Trig | Alg | Geom | Calc |
|---|---|---|---|
| 1.3 | 1.3 | 3.7 | 2.3 |
| 4.0 | 2.0 | 2.3 | |
| 1.3 | 1.0 | 3.0 |
Susie
Jay
Lara
| Last | ID | Uni | Cats |
|---|---|---|---|
| Jones | 45 | TUM | 0 |
| Sun | 48 | LMU | 6 |
| Blue | 66 | LMU | 1 |
grades
students
Susie
Jay
Lara
unis
LMU
Ulm
TUM
| City | Students | Courses |
|---|---|---|
| Munich | [48, 66] | [Trig, Alg] |
| Munich | [45] | [Geom, Calc] |
| Ulm | [] | [Trig, Alg, Calc] |
courses
Geo
Alg
Trig
| ID | Prof ID | Students |
|---|---|---|
| 1 | 44 | [45, 48, 66] |
| 2 | 154 | [45, 66] |
| 3 | 22 | [45, 48] |
Relational Databases
SQL: For when you have lots of data which interconnects in complex ways!
SQL Databases run the world!
Many database formats use SQL
The main trio:
Let's look at a real-life example
Movie rental store 🍿
Let's look at a real-life example
Let's move into the notebook now:
[URL SOON]
Let's look at a real-life example
Download the dataset:
https://www.kaggle.com/api/v1/datasets/download/atanaskanev/sqlite-sakila-sample-database
APIs
Application Programming Interface
Think of APIs like a waiter at a restaurant
“I can’t honestly recommend anything – I’ve watched them make the stuff.”
Roy Fox — May 1, 1954
APIs
Application Programming Interface
Think of APIs like a waiter at a restaurant:
APIs
Application Programming Interface
APIs
Application Programming Interface
Most APIs are accessed with URLs:
http://reddit.com/api/r/python/new
Let's go over to the notebook and try using some APIs ourselves!
Challenge #2
locations = {
"Berlin": {
"latitude": 52.52,
"longitude": 13.41
},
"Paris": {
"latitude": 48.85,
"longitude": 2.35
},
"Rome": {
"latitude": 41.90,
"longitude": 12.48
}
}
Monte Carlo (MC) Methods
Started at Los Alamos as a way to model neutron diffusion
Needed a code name for this method 🕵️♂️
Monte Carlo (MC) Methods
Use random sampling to estimate a very complicated probability distribution
Simple example:
Let's code it up!
Monte Carlo (MC) Methods
That was easy to calculate by hand... but what about this?
Let's code it up!
Challenge #2
That was easy to calculate by hand... but what about this?
You can use a for loop if it helps conceptually.
For an extra challenge, try and do it only with vectors 💪
MC in the real world
Imagine you want to determine the habitability or other properties of star systems. This depends on many things:
Given the observations we have of stars and exoplanets, we could reasonably estimate the distributions of each of these parameters
MC in the real world
Imagine you want to determine the habitability or other properties of star systems. This depends on many things:
Distributions of attribute from observations
Draw initial parameters and simulate many examples with MC
MC in the real world
Imagine you want to determine the habitability of star systems. This depends many things including:
Distributions of attribute from observations
Draw initial parameters and simulate many examples with MC
scipy
Algorithms for:
scipy
Most algorithms are written in:
and then "wrapped" in Python.
install scipy
uv add scipy
Things we will try today:
scipy.constants
scipy.stats
scipy.integrate
scipy.interpolate
scipy.optimize
scipy.fft
Back to the notebook we go!
The End