Open up a NEW NOTEBOOK

Have it be in the same directory as CD_Transactions_07-23-2017.CSV

Open up a SHELL

cd to the same directory as CD_Transactions_07-23-2017.CSV.

ls
03-classwork.zip                indiv_header_file.csv
CD_Transactions_07-23-2017.CSV  links.txt
Sqlite and pandas.ipynb
import pandas as pd
%%time
df = pd.read_csv("CD_Transactions_07-23-2017.CSV")
df.head()
CPU times: user 3.17 s, sys: 278 ms, total: 3.45 s
Wall time: 3.51 s
# .import CD_Transactions_07-23-2017.CSV contribs
ls
03-classwork.zip                alaska.db
CD_Transactions_07-23-2017.CSV  indiv_header_file.csv
Sqlite and pandas.ipynb         links.txt
import sqlite3
# Connect to our database
conn = sqlite3.connect("alaska.db")
%%time
# Make our query, get the results from the database
# give it the QUERY and give it the CONNECTION
df = pd.read_sql("SELECT * FROM contribs", conn)
CPU times: user 6.42 s, sys: 1.08 s, total: 7.5 s
Wall time: 8.68 s
df.head()
Result Date Transaction Type Payment Type Payment Detail Amount Last/Business Name First Name Address City ... -------- Report Type Election Name Election Type Municipality Office Filer Type Name Report Year Submitted
0 1 4/3/2017 Income Check 12864 $350.00 Alaska Republican Party State Account ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of School Board Candidate Kay E Schuster 2017 4/3/2017
1 2 4/3/2017 Income Credit Card $500.00 Coffey Dan ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of School Board Candidate Kay E Schuster 2017 4/3/2017
2 3 4/3/2017 Income Check 3047 $300.00 ACS Employees PAC ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Assembly Candidate Pete Petersen 2017 4/3/2017
3 4 4/3/2017 Income Credit Card $500.00 Holmes Patrick ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Group Alaska Republican Party 2017 4/3/2017
4 5 4/3/2017 Income Credit Card $500.00 Gonzales Mark L. ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Group Alaska Republican Party 2017 4/3/2017

5 rows × 26 columns

%%time
# df[df.Office == 'School Board'].head()
df = pd.read_sql("SELECT * FROM contribs WHERE Office = 'School Board'", conn)
df.head()
CPU times: user 45.2 ms, sys: 7.88 ms, total: 53.1 ms
Wall time: 69.8 ms
df = pd.read_sql("SELECT * FROM contribs", conn)
df.head()
Result Date Transaction Type Payment Type Payment Detail Amount Last/Business Name First Name Address City ... -------- Report Type Election Name Election Type Municipality Office Filer Type Name Report Year Submitted
0 1 4/3/2017 Income Check 12864 $350.00 Alaska Republican Party State Account ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of School Board Candidate Kay E Schuster 2017 4/3/2017
1 2 4/3/2017 Income Credit Card $500.00 Coffey Dan ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of School Board Candidate Kay E Schuster 2017 4/3/2017
2 3 4/3/2017 Income Check 3047 $300.00 ACS Employees PAC ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Assembly Candidate Pete Petersen 2017 4/3/2017
3 4 4/3/2017 Income Credit Card $500.00 Holmes Patrick ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Group Alaska Republican Party 2017 4/3/2017
4 5 4/3/2017 Income Credit Card $500.00 Gonzales Mark L. ... 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Group Alaska Republican Party 2017 4/3/2017

5 rows × 26 columns

df.to_csv("../just-alaska.csv", index=False)
pd.set_option("display.max_columns", 100)
df.head()
Result Date Transaction Type Payment Type Payment Detail Amount Last/Business Name First Name Address City State Zip Country Occupation Employer Purpose of Expenditure -------- Report Type Election Name Election Type Municipality Office Filer Type Name Report Year Submitted
0 1 4/3/2017 Income Check 12864 $350.00 Alaska Republican Party State Account Alaska USA N/A N/A 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of School Board Candidate Kay E Schuster 2017 4/3/2017
1 2 4/3/2017 Income Credit Card $500.00 Coffey Dan Alaska USA Attorney Self-Employed 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of School Board Candidate Kay E Schuster 2017 4/3/2017
2 3 4/3/2017 Income Check 3047 $300.00 ACS Employees PAC Alaska USA PAC PAC 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Assembly Candidate Pete Petersen 2017 4/3/2017
3 4 4/3/2017 Income Credit Card $500.00 Holmes Patrick Alaska USA Associate Manager Juneau 1 LLC Individual Contribution 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Group Alaska Republican Party 2017 4/3/2017
4 5 4/3/2017 Income Credit Card $500.00 Gonzales Mark L. Alaska USA Executive Alcohol Detection Services of Alaska Individual Contribution 24 Hour Report 2017 - Anchorage Municipal Election Anchorage Municipal Anchorage, Municipality of Group Alaska Republican Party 2017 4/3/2017
df['First Name'].value_counts()
                   24751
J                   7229
Michael             4881
D                   4514
John                4296
R                   4170
Robert              4127
C                   3892
M                   3876
James               3722
David               3443
S                   3222
A                   2804
B                   2793
T                   2615
William             2222
K                   2182
Richard             2114
MICHAEL             2082
JAMES               1986
Brian               1845
Daniel              1839
JOHN                1779
L                   1728
G                   1672
Mark                1665
Eric                1641
ROBERT              1607
Scott               1588
Thomas              1568
                   ...  
Cassamdra              1
AERIALE                1
Mildred P.             1
MYLA                   1
Woolsey                1
CAROL ANN              1
SHAWNAH                1
M R                    1
Kelin                  1
LEA  B                 1
META                   1
Oran                   1
ETHAN                  1
Caherine               1
Zuzanna                1
Darrelle               1
Debe                   1
ROBERTO                1
Ilaura                 1
MARNI                  1
 Jake                  1
Hugh (Bud)             1
 Ervon                 1
Saraya                 1
 Boko                  1
JOYLLE                 1
EUNSUK                 1
Chappel                1
CATHARINE              1
Gabriel                1
Name: First Name, Length: 15813, dtype: int64