Skip to content

Commit 6cc51f1

Browse files
committed
08-working-with-sql: fix metadata & code blocks
1 parent 57f0896 commit 6cc51f1

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

_episodes/08-working-with-sql.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
title: Accessing SQLite Databases Using Python and Pandas
33
teaching: 20
44
exercises: 25
5-
5+
questions:
6+
- "FIXME"
67
objectives:
7-
- Use the sqlite3 module to interact with a SQL database.
8-
- Access data stored in SQLite using Python.
9-
- Describe the difference in interacting with data stored as a CSV file versus in SQLite.
10-
- Describe the benefits of accessing data using a database compared to a CSV file.
8+
- "Use the sqlite3 module to interact with a SQL database."
9+
- "Access data stored in SQLite using Python."
10+
- "Describe the difference in interacting with data stored as a CSV file versus in SQLite."
11+
- "Describe the benefits of accessing data using a database compared to a CSV file."
12+
keypoints:
13+
- "FIXME"
1114
---
1215

1316
## Python and SQL
@@ -30,7 +33,7 @@ perform all kinds of operations with `.execute()`.
3033

3134
[sqlite3]: https://docs.python.org/3/library/sqlite3.html
3235

33-
```python
36+
~~~
3437
import sqlite3
3538
3639
# Create a SQL connection to our SQLite database
@@ -44,7 +47,8 @@ for row in cur.execute('SELECT * FROM species;'):
4447
4548
# Be sure to close the connection
4649
con.close()
47-
```
50+
~~~
51+
{: .language-python}
4852

4953
### Queries
5054

@@ -53,7 +57,7 @@ retrieving data based on some search parameters. Use a SELECT statement string.
5357
The query is returned as a single tuple or a tuple of tuples. Add a WHERE
5458
statement to filter your results based on some parameter.
5559

56-
```python
60+
~~~
5761
import sqlite3
5862
5963
# Create a SQL connection to our SQLite database
@@ -71,15 +75,16 @@ cur.fetchone()
7175
7276
# Be sure to close the connection
7377
con.close()
74-
```
78+
~~~
79+
{: .language-python}
7580

7681
## Accessing data stored in SQLite using Python and Pandas
7782

7883
Using pandas, we can import results of a SQLite query into a dataframe. Note
7984
that you can use the same SQL commands / syntax that we used in the SQLite
8085
lesson. An example of using pandas together with sqlite is below:
8186

82-
```python
87+
~~~
8388
import pandas as pd
8489
import sqlite3
8590
@@ -91,7 +96,8 @@ df = pd.read_sql_query("SELECT * from surveys", con)
9196
print(df.head())
9297
9398
con.close()
94-
```
99+
~~~
100+
{: .language-python}
95101

96102
## Storing data: CSV vs SQLite
97103

@@ -118,7 +124,7 @@ benchmarks]).
118124

119125
We can also us pandas to create new tables within an SQLite database. Here, we run we re-do an excercise we did before with CSV files using our SQLite database. We first read in our survey data, then select only those survey results for 2002, and then save it out to its own table so we can work with it on its own later.
120126

121-
```python
127+
~~~
122128
import pandas as pd
123129
import sqlite3
124130
@@ -134,7 +140,8 @@ surveys2002 = surveys_df[surveys_df.year == 2002]
134140
surveys2002.to_sql("surveys2002", con, if_exists="replace")
135141
136142
con.close()
137-
```
143+
~~~
144+
{: .language-python}
138145

139146
> ## Challenge - Saving your work
140147
>

0 commit comments

Comments
 (0)