Templates
Our course project template can be found here, or on Scholar:
/depot/datamine/apps/templates/project_template.ipynb
Students in STAT 19000, 29000, and 39000 can use and modify this as a template as needed, for all project submissions. This template is a starting point for all projects.
Most of the time, this template will be used with the f2021-s2022 or f2021-s2022-r kernel. By default, the f2021-s2022 kernel runs Python code and the f2021-s2022-r kernel runs R code. To run other types of code, see below. Any format or template related questions should be asked in Piazza.
Running R
code using the f2021-s2022
kernel
-
First, load the
rpy2.ipython
extension.%load_ext rpy2.ipython
-
Next, to run R code, in a new cell, run the following.
%%R my_vec <- c(1,2,3) my_vec
As you can see, any cell that begins with %%R
will run the R code in that cell. If a cell does not begin with %%R
, it will be assumed that the code is Python code, and run accordingly.
Running SQL queries using the f2021-s2022
kernel
-
First, load the sql extension.
%load_ext sql
-
Next, you need to establish a connection with the database. If this is a sqlite database, you can use the following command.
%sql sqlite:///my_db.db # or %sql sqlite:////home/class/datamine/path/to/my_db.db
Otherwise, if this is a mysql database, you can use the following command.
%sql mariadb+pymysql://username:[email protected]_url.com/my_database
-
Next, to run SQL queries, in a new cell, run the following.
%%sql SELECT * FROM my_table;
As you can see, any cell that begins with %%sql
will run the SQL query in that cell. If a cell does not begin with %%sql
, it will be assumed that the code is Python code, and run accordingly.
Running bash
code using the f2021-s2022
kernel
To run bash
code, in a new cell, run the following.
%%bash
ls -la
As you can see, any cell that begins with %%bash
will run the bash
code in that cell. If a cell does not begin with %%bash
, it will be assumed that the code is Python code, and run accordingly.
Code cells that start with The commands listed in the "line" section are run with a single
The commands listed in the "cell" section are run with a double You can read more about some of the available magics in the official documentation. |
Including an image in your notebook
To include an image in your notebook, use the following Python code.
from IPython import display
display.Image("./cloud.png")
Here, ./cloud.png
is the path to the image you would like to include.
If you choose to include an image using a Markdown cell, and the |