Skip to content
Snippets Groups Projects
Commit 31729872 authored by Anna Meyer's avatar Anna Meyer
Browse files

exam review

parent a140f559
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:c3f52922 tags:
``` python
import pandas as pd
from bs4 import BeautifulSoup
import sqlite3
```
%% Cell type:code id:0c34e6b0 tags:
%% Cell type:markdown id:5c9d1d79 tags:
``` python
```
# Big picture review
Series vs dataframe vs database
%% Cell type:code id:69afd613 tags:
``` python
```
%% Cell type:markdown id:e5f11a12 tags:
# Pandas
%% Cell type:code id:4ebb9401 tags:
``` python
fish = {"Name":"fish", "color":"green", "length":8, "habitat":'water'}
cat = {"Name":"cat","color":"brown","length":15,"habitat":'house'}
tiger = {"Name":'tiger', 'color':'orange', 'length':48, 'habitat':'jungle'}
dog = {"Name":'dog','color':'yellow','length':28,'habitat':'house'}
animals = pd.DataFrame([fish,cat,tiger,dog])
animals
```
%% Cell type:code id:35f32b68 tags:
``` python
# DataFrame vs Series
```
%% Cell type:code id:a7bb549c tags:
``` python
# Filtering - simple and complex conditions
```
%% Cell type:code id:f6f7d185 tags:
``` python
# Accessing individual values
```
%% Cell type:code id:2f6f8f41 tags:
``` python
# Understanding loc, iloc, and slicing
```
%% Cell type:code id:62ccdd15 tags:
``` python
# Setting an index column
```
%% Cell type:markdown id:f9fdb089 tags:
# Web
%% Cell type:markdown id:b598dd65 tags:
<table>
<tr>
<th>University</th>
<th>Department</th>
</tr>
<tr>
<td>UW-Madison</td>
<td><a href = "https://www.cs.wisc.edu/">Computer Sciences</a></td>
</tr>
<tr>
<td>UW-Madison</td>
<td><a href = "https://stat.wisc.edu/">Statistics</a></td>
</tr>
<tr>
<td>UW-Madison</td>
<td><a href = "https://cdis.wisc.edu/">CDIS</a></td>
</tr>
<tr>
<td>UC Berkeley</td>
<td><a href = "https://eecs.berkeley.edu/">Electrical Engineering and Computer Sciences</a></td>
</tr>
</table>
%% Cell type:code id:8b44c2dd tags:
``` python
html_string = """
<table>
<tr>
<th>University</th>
<th>Department</th>
</tr>
<tr>
<td>UW-Madison</td>
<td><a href = "https://www.cs.wisc.edu/">Computer Sciences</a></td>
</tr>
<tr>
<td>UW-Madison</td>
<td><a href = "https://stat.wisc.edu/">Statistics</a></td>
</tr>
<tr>
<td>UW-Madison</td>
<td><a href = "https://cdis.wisc.edu/">CDIS</a></td>
</tr>
<tr>
<td>UC Berkeley</td>
<td>
<a href = "https://eecs.berkeley.edu/">Electrical Engineering and Computer Sciences
</a>
</td>
</tr>
</table>
"""
```
%% Cell type:code id:83ac470b tags:
``` python
bs_obj = BeautifulSoup(html_string, 'html.parser')
```
%% Cell type:code id:c546e7b8 tags:
``` python
```
%% Cell type:code id:be3d05e0 tags:
``` python
# get_text, children, attrs
```
%% Cell type:markdown id:753cf273 tags:
# Databases
%% Cell type:code id:4fda7cf8 tags:
``` python
assert os.path.exists("movies.db")
conn = sqlite3.connect("movies.db")
def qry(QUERY):
'''QUERY is a string containing SQL, conn is a global connection variable'''
return pd.read_sql(QUERY, conn)
```
%% Cell type:markdown id:f98c2f0c tags:
where vs having
%% Cell type:code id:a76a21e2 tags:
``` python
```
%% Cell type:markdown id:984915b2 tags:
# Review
%% Cell type:markdown id:f4fc528d tags:
Code flow
%% Cell type:code id:aba2a0a6 tags:
``` python
# Look at examples with python tutor
#. # if/elif/else
#. # try/except
# #. simple recursive function
```
%% Cell type:markdown id:5435a2eb tags:
Parameters and functions
%% Cell type:code id:fc8d4c25 tags:
``` python
def greeting(name, salutation = 'Hello', punctuation='!'):
print(salutation, name, punctuation)
```
%% Cell type:code id:8bd6614f tags:
``` python
```
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment