In [34]:
import sqlite3
import pandas
con = sqlite3.connect('2016.db')
table = pandas.read_sql("select avg(heat_input), avg(gload), op_hour from data where fuel_actual is 'NG' and state is 'CA' and substr(op_date, 1, 2) is '06' group by op_hour", con)
table.to_csv('ca_ng_june.csv')

In [ ]:
import sqlite3
import pandas
con = sqlite3.connect('2016.db')
table = pandas.read_sql("select substr(op_date, 1, 2) as month, name, orispl_code, unitid, avg(heat_input) as avg_heat, avg(gload) as avg_gen, op_hour from data where fuel_actual is 'NG' and state is 'CA'  group by op_hour, substr(op_date, 1, 2), orispl_code, unitid ", con)
table.to_csv('ca_ng_june.csv')

In [11]:
import sqlite3
import pandas
con = sqlite3.connect('2016.db')
table = pandas.read_sql("select * from ( \
                        select avg(gload), op_hour from data where fuel_actual is 'NG' and state is 'CA' and substr(op_date, 1, 2) is '06' group by op_hour ) as a \
                        , data as ", con)
table.to_csv('ca_ng_june.csv')

In [12]:
%sql sqlite:///2016.db


Out[12]:
u'Connected: None@2016.db'

In [20]:
%sql select gload, heat_input, unitid, op_date, op_hour from data where name is 'Colstrip' and substr(op_date, 1, 2) is '06' order by unitid limit 5


Done.
Out[20]:
gload heat_input unitid op_date op_hour
175.0 1910.5 1 06-01-2016 0
161.0 1831.7 1 06-01-2016 1
162.0 1849.3 1 06-01-2016 2
162.0 1859.0 1 06-01-2016 3
162.0 1843.4 1 06-01-2016 4

In [ ]: