Look At The Data¶
So far, we have created a table and inserted three records into it.
To see the results, we've had to install a separate piece of software. It would be much nicer to use Python to show us the content of our database.
Let's connect to our database:
In [5]:
import sqlalchemy as sa
engine = sa.create_engine('sqlite:///flight.db')
connection = engine.connect()
We'll use the Pandas library to import data from our database and view it in our Jupyter notebook.
Pandas has a two dimensional structure called a 'dataframe' which has many similarities to a database table.
It also has a 'read_sql' function which takes two arguments:
- a table name
- an sqlalchemy connection object
read_sql
returns a pandas dataframe which we can then display.
First, let's import the pandas library:
In [6]:
import pandas as pd
Now we can call read_sql
and pass it the name of our table and our connection object:
In [7]:
pd.read_sql('readings', connection)
Out[7]:
flight | ts | temp | pressure | humidity | accel_x | accel_y | accel_z | |
---|---|---|---|---|---|---|---|---|
0 | hab1 | 2015-01-01 09:00:00 | 25.5 | 1020 | 40 | 0.0 | 0.0 | 0.0 |
1 | hab1 | 2015-01-01 09:01:00 | 25.5 | 1019 | 40 | 0.0 | 0.0 | 0.0 |
2 | hab1 | 2015-01-01 09:02:00 | 25.5 | 1019 | 41 | 0.0 | 0.0 | 0.0 |