Skip to content

Instantly share code, notes, and snippets.

View ckashby's full-sized avatar

C K Ashby ckashby

View GitHub Profile
import sqlite3
import pandas as pd
conn = sqlite3.connect("ladder.db")
# pd.read_sql("SELECT * FROM mytable;", conn)
import sqlite3
import pandas as pd
conn = sqlite3.connect("ladder.db")
# pd.read_sql("SELECT * FROM mytable;", conn)
# pd.read_sql("SELECT * FROM pets;", conn)
# pd.read_sql("SELECT * FROM employees;", conn)
# ## Aggregating Statistics with GROUP BY
# 45) What is the average age of `pets` by species?
pd.read_sql("SELECT AVG(age) FROM pets GROUP BY species;", conn)
# dogs 6.5, cat 4.3, lobster 3
# 46) Repeat the previous problem but make sure the species label is also displayed!
pd.read_sql("SELECT species, AVG(age) FROM pets GROUP BY species;", conn)
# Assume this behavior is always being asked of you any time you use `GROUP BY`.
# 47) What is the count, mean, minimum, and maximum age by species in `pets`?
pd.read_sql("SELECT species, COUNT(age), AVG(age), MIN(age), MAX(age) FROM pets GROUP BY species;", conn)
# ## Aggregating Statistics with GROUP BY
# 45) What is the average age of `pets` by species?
pd.read_sql("SELECT AVG(age) FROM pets GROUP BY species;", conn)
# dogs 6.5, cat 4.3, lobster 3
# 46) Repeat the previous problem but make sure the species label is also displayed!
pd.read_sql("SELECT species, AVG(age) FROM pets GROUP BY species;", conn)
# Assume this behavior is always being asked of you any time you use `GROUP BY`.
# 47) What is the count, mean, minimum, and maximum age by species in `pets`?
pd.read_sql("SELECT species, COUNT(age), AVG(age), MIN(age), MAX(age) FROM pets GROUP BY species;", conn)
# ## Summary Statistics
# 32) How many rows are in the `pets` table?
pd.read_sql("SELECT COUNT(*) FROM pets;", conn)
# 13
# 33) How many female pets are in the `pets` table?
pd.read_sql("SELECT COUNT(*) FROM pets WHERE sex = 'F'", conn)
# 7
# 34) How many female cats are in the `pets` table?
pd.read_sql("SELECT COUNT(*) FROM pets WHERE sex = 'F' AND species = 'cat'", conn)
# 4
import sqlite3
import pandas as pd
conn = sqlite3.connect("ladder.db")
# pd.read_sql("SELECT * FROM mytable;", conn)
# pd.read_sql("SELECT * FROM pets;", conn)
# pd.read_sql("SELECT * FROM employees;", conn)
# pd.read_sql("SELECT * FROM transactions;", conn)
pd.read_sql("SELECT * FROM yum;", conn)
students = [
{"lname": "Kalama", "fname": "Samuel"},
{"lname": "Kalani", "fname": "Shawn"},
{"lname": "Kona", "fname": "Sid"},
{"lname": "Kapena", "fname": "Stan"},
]
@ckashby
ckashby / bs4_checkbox_does_not_toggle
Created June 29, 2018 23:37
Test file to show Bootstrap 4.1.1 bug. Clicking on checkbox button's checkbox square is not toggling checkbox.
<!-- Load in Chrome Version 67.0.3396.87 (Official Build) (64-bit) on Mac OS 10.13.5 -->
<!-- Click on the white square in the button that is the checkbox. It will NOT toggle. Click on button toggles. -->
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="checkbox" checked autocomplete="off"> Checkbox 1 (pre-checked)
</label>
<label class="btn btn-primary">
<input type="checkbox" autocomplete="off"> Checkbox 2
@ckashby
ckashby / Android Common Intents
Created August 8, 2014 21:54
Android - Common Implicit Intents
Phone Call
Permissions:
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:0377778888"));
startActivity(callIntent);
@ckashby
ckashby / Action Bar 2 menu items
Created August 4, 2014 19:25
Action Bar 2 menu items
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/miCompose"
android:icon="@drawable/ic_compose"
android:showAsAction="ifRoom"
android:title="Compose">
</item>
<item
android:id="@+id/miProfile"
android:icon="@drawable/ic_profile"