In [1]:
# !pip install ipython-sql
In [2]:
from IPython.display import display_javascript
js = "IPython.CodeCell.config_defaults.highlight_modes['magic_sql'] = {'reg':[/^%%sql/]};"
display_javascript(js, raw=True)
In [3]:
%load_ext sql
In [4]:
%sql sqlite://
Out[4]:
In [5]:
%%sql
DROP TABLE writer;
CREATE TABLE writer(first_name, last_name, year_of_death);
insert into writer VALUES('William', 'Shakespeare', 1616);
insert into writer VALUES('Bertold', 'Brecht', 1956);
In [6]:
%sql select * from writer;
In [7]:
%%sql
insert into writer VALUES('Walt', 'Whitman', 1856);
insert into writer VALUES('Mark', 'Twain', 1907);
In [12]:
%%sql
select * from writer order by year_of_death;
Out[12]:
In [13]:
result = %sql SELECT * FROM writer ORDER BY year_of_death;
In [15]:
type(result)
Out[15]:
In [16]:
result.DataFrame()
Out[16]:
In [18]:
%matplotlib inline
result.bar()
Out[18]:
>>> print('hello')
In [ ]: