Archie  Clayton

Archie Clayton


A Beginner’s Tutorial to Jupyter Notebooks

Use Jupyter Notebooks for interactive Data Science Projects

A Jupyter Notebook is a powerful tool for interactively developing and presenting Data Science projects. Jupyter Notebooks integrate your code and its output into a single document. That document will contain the text, mathematical equations, and visualisations that the code produces directly in the same page.

This step-by-step workflow promotes fast, iterative development since each output of your code will be displayed right away. That’s why notebooks have become increasingly popular over the last several years, especially in Data Science. Kaggle Kernels are almost exclusively made with Jupyter Notebooks these days.

This article is aimed at beginners looking to get started with Jupyter Notebooks. We’ll go through it all end-to-end: Installation, Basic Usage, and how to create an interactive Data Science project!

Setting up a Jupyter Notebook

To get started with Jupyter Notebooks you’ll need to install the Jupyter library from Python. The easiest way to do this is via pip:

pip3 install jupyter

I always recommend using pip3 over pip2 these days since Python 2 won’t be supported anymore starting January 1, 2020.

Now that you have Jupyter installed let’s learn how to use it! To get started, use your terminal to move into the folder you would like to work from using the cd command (Linux or Mac). Then start up Jupyter with the following command:

jupyter notebook

This will start up a Jupyter server and your browser will open up a new tab to the following URL: http://localhost:8888/tree. It’ll look a little something like this:

Great! We’ve got our Jupyter server up and running. Now we can start building our notebook and filling it up with code!

The Basics of Jupyter Notebooks

To create a notebook, click on the “new” menu in the top right and select “Python 3”. At this point your web-page will look similar to this:

You’ll notice that at the top of your page is the word *Untitled *next to the Jupyter icon — this is the title of your Notebook. Let’s change it to something a little more descriptive. Just move your mouse over the word Untitled and click on the text. You should now see an in-browser dialog where you can rename your Notebook. I’m calling mine George’s Notebook.

Let’s start writing some code!

Notice how the first line of your Notebook is marked with an In [] next to it. That keyword specifies that what you are going to type is an input. Let’s try writing a simply print statement there. Recall that your print statement must have Python 3 syntax since this is a Python 3 Notebook. Once you write your print statement in the cell, press the Run button.

Awesome! See how the output is printed directly on the notebook. This is how we can do an interactive project by seeing the output at each step of the process.

Also notice that when you ran the cell, the first line which had an In [] next to it has now changed to In [1] . The number inside the square brackets indicates the order in which the cell was ran; the first cell has a 1 because it was the first cell that we ran. We can run each cell individually at anytime and those numbers will change.

Let’s take an example.We’re going to set up 2 cells, each one with a different print statement. We’ll run the second print statement first following by the first print statement. Take a look at how the number inside the squared brackets changed as a result.

When you have multiple cells in your Notebook and you run the cells in order, you can share your variables and imports across cells. This makes it easy to separate out your code into related sections without needing to re-create variable at every cell. Just be sure that you run your cells in the proper order so that all your variables are created before usage.

Adding Descriptive Text to Your Notebook

Jupyter Notebooks come with a great set of tools for adding descriptive text to your notebooks. Not only can you write comments, but you can also add titles, lists, bold, and italics. All of this is done in the super easy Markdown format.

The first thing to do is to change the cell type — click the drop down menu that says “Code” on it and change it to “Markdown”. This changes the type of cell we are working with.

Let’s try out a couple of the options. We can create titles using the # symbol. A single # will make the biggest title and adding more #s will create a smaller and smaller title.

We can italicise our text using a single star on either side or bold it using a double star. Creating a list is easy with a simple dash - and space beside each list item.

Interactive Data Science

Let’s do a quick running example of how to create an interactive Data Science project. This notebook and code comes from an actual project I did.

I start out with a Markdown cell and put up a title with the biggest header by using a single # . I then create a list and description of all the important libraries I’m about to import.

Next comes the first code cell which imports all of the relevant libraries. This will be standard Python Data Science code except for 1 additional item: in-order to see your Matplotlib visualisations directly within the notebook, you’ll need to add the following line: %matplotlib inline .

Next I’m going to import a dataset from a CSV file and print out the first 10 items. Notice in the screenshot below how Jupyter automatically shows the .head() function’s output as a table — Jupyter works beautifully with the Pandas library!

Now we’ll create a figure and plot it directly in our notebook. Since we’ve added the line %matplotlib inline above, anytime we run a our figure will be displayed directly in our notebook!

Also notice how all of the variables from previous cells, particularly the dataframe which we read from CSV, carries over to future cells as long as we pressed the “Run” button on those previous cells.

Voila! That’s the easy way to create an interactive Data Science project!

The Menus

The Jupyter server has several menus that you can use to get the most out of your project. These menus enable you to interact with your notebook, as well as access documentation for popular Python libraries and export your project into a format for external presentation.

The File menu allows you to create, copy, rename, and save your notebooks to file. The most notable item in the File menu is the Download as drop down menu which lets you download your notebook in a variety of formats including pdf, html, and slides — perfect for creating a presentation!

The Edit menu lets you do the good’ol can cut, copy, and paste of code. You can also reorder cells here, perhaps if you’re creating a notebook for an interactive presentation and want to show your audience things in a certain order.

The View menu lets you play around with things like displaying line numbers and modifying the toolbar. The best feature in this menu is definitely the Cell Toolbar where you can add tags, notes, and attachments to each cell. You can even select the formatting you would want for this cell if you turned the notebook into a slide show!

The Insert menu is just for inserting cells above or below the currently selected cell. The Cell menu is where you go to run your cells in a specific order or change the cell type.

Finally you have the Help menu which is one of my personal favourites! The help menu gives you direct access to important documentation. You’ll be able to learn about all the Jupyter Notebook shortcuts to speed up your workflow. You also get convenient links to the documentation of some of the most important Python libraries including Numpy, Scipy, Matplotlib, and Pandas!

#data-science #machine-learning #python

What is GEEK

Buddha Community

A Beginner’s Tutorial to Jupyter Notebooks
Myriam  Rogahn

Myriam Rogahn


How to Use Jupyter Notebook in 2020: A Beginner’s Tutorial

What is Jupyter Notebook?

The Jupyter Notebook is an incredibly powerful tool for interactively developing and presenting data science projects. This article will walk you through how to use Jupyter Notebooks for data science projects and how to set it up on your local machine.

First, though: what is a “notebook”?

A notebook integrates code and its output into a single document that combines visualizations, narrative text, mathematical equations, and other rich media. In other words: it’s a single document where you can run code, display the output, and also add explanations, formulas, charts, and make your work more transparent, understandable, repeatable, and shareable.

Using Notebooks is now a major part of the data science workflow at companies across the globe. If your goal is to work with data, using a Notebook will speed up your workflow and make it easier to communicate and share your results.

Best of all, as part of the open source Project Jupyter, Jupyter Notebooks are completely free. You can download the software on its own, or as part of the Anaconda data science toolkit.

Although it is possible to use many different programming languages in Jupyter Notebooks, this article will focus on Python, as it is the most common use case. (Among R users, R Studio tends to be a more popular choice).

How to Follow This Tutorial

To get the most out of this tutorial you should be familiar with programming — Python and pandas specifically. That said, if you have experience with another language, the Python in this article shouldn’t be too cryptic, and will still help you get Jupyter Notebooks set up locally.

Jupyter Notebooks can also act as a flexible platform for getting to grips with pandas and even Python, as will become apparent in this tutorial.

We will:

  • Cover the basics of installing Jupyter and creating your first notebook
  • Delve deeper and learn all the important terminology
  • Explore how easily notebooks can be shared and published online.

(In fact, this article was written as a Jupyter Notebook! It’s published here in read-only form, but this is a good example of how versatile notebooks can be. In fact, most of our programming tutorials and even our Python courses were created using Jupyter Notebooks).

#data science tutorials #beginner #jupyter #jupyter notebooks #learn python #pandas #python #tutorial #tutorials

Jeromy  Lowe

Jeromy Lowe


Data Visualization in R with ggplot2: A Beginner Tutorial

A famous general is thought to have said, “A good sketch is better than a long speech.” That advice may have come from the battlefield, but it’s applicable in lots of other areas — including data science. “Sketching” out our data by visualizing it using ggplot2 in R is more impactful than simply describing the trends we find.

This is why we visualize data. We visualize data because it’s easier to learn from something that we can see rather than read. And thankfully for data analysts and data scientists who use R, there’s a tidyverse package called ggplot2 that makes data visualization a snap!

In this blog post, we’ll learn how to take some data and produce a visualization using R. To work through it, it’s best if you already have an understanding of R programming syntax, but you don’t need to be an expert or have any prior experience working with ggplot2

#data science tutorials #beginner #ggplot2 #r #r tutorial #r tutorials #rstats #tutorial #tutorials

Willie  Beier

Willie Beier


Tutorial: Getting Started with R and RStudio

In this tutorial we’ll learn how to begin programming with R using RStudio. We’ll install R, and RStudio RStudio, an extremely popular development environment for R. We’ll learn the key RStudio features in order to start programming in R on our own.

If you already know how to use RStudio and want to learn some tips, tricks, and shortcuts, check out this Dataquest blog post.

Table of Contents

#data science tutorials #beginner #r tutorial #r tutorials #rstats #tutorial #tutorials

Tutorial: Loading and Cleaning Data with R and the tidyverse

1. Characteristics of Clean Data and Messy Data

What exactly is clean data? Clean data is accurate, complete, and in a format that is ready to analyze. Characteristics of clean data include data that are:

  • Free of duplicate rows/values
  • Error-free (e.g. free of misspellings)
  • Relevant (e.g. free of special characters)
  • The appropriate data type for analysis
  • Free of outliers (or only contain outliers have been identified/understood), and
  • Follows a “tidy data” structure

Common symptoms of messy data include data that contain:

  • Special characters (e.g. commas in numeric values)
  • Numeric values stored as text/character data types
  • Duplicate rows
  • Misspellings
  • Inaccuracies
  • White space
  • Missing data
  • Zeros instead of null values

2. Motivation

In this blog post, we will work with five property-sales datasets that are publicly available on the New York City Department of Finance Rolling Sales Data website. We encourage you to download the datasets and follow along! Each file contains one year of real estate sales data for one of New York City’s five boroughs. We will work with the following Microsoft Excel files:

  • rollingsales_bronx.xls
  • rollingsales_brooklyn.xls
  • rollingsales_manhattan.xls
  • rollingsales_queens.xls
  • rollingsales_statenisland.xls

As we work through this blog post, imagine that you are helping a friend launch their home-inspection business in New York City. You offer to help them by analyzing the data to better understand the real-estate market. But you realize that before you can analyze the data in R, you will need to diagnose and clean it first. And before you can diagnose the data, you will need to load it into R!

3. Load Data into R with readxl

Benefits of using tidyverse tools are often evident in the data-loading process. In many cases, the tidyverse package readxl will clean some data for you as Microsoft Excel data is loaded into R. If you are working with CSV data, the tidyverse readr package function read_csv() is the function to use (we’ll cover that later).

Let’s look at an example. Here’s how the Excel file for the Brooklyn borough looks:

The Brooklyn Excel file

Now let’s load the Brooklyn dataset into R from an Excel file. We’ll use the readxlpackage. We specify the function argument skip = 4 because the row that we want to use as the header (i.e. column names) is actually row 5. We can ignore the first four rows entirely and load the data into R beginning at row 5. Here’s the code:

library(readxl) # Load Excel files
brooklyn <- read_excel("rollingsales_brooklyn.xls", skip = 4)

Note we saved this dataset with the variable name brooklyn for future use.

4. View the Data with tidyr::glimpse()

The tidyverse offers a user-friendly way to view this data with the glimpse() function that is part of the tibble package. To use this package, we will need to load it for use in our current session. But rather than loading this package alone, we can load many of the tidyverse packages at one time. If you do not have the tidyverse collection of packages, install it on your machine using the following command in your R or R Studio session:


Once the package is installed, load it to memory:


Now that tidyverse is loaded into memory, take a “glimpse” of the Brooklyn dataset:

## Observations: 20,185
## Variables: 21
## $ BOROUGH <chr> "3", "3", "3", "3", "3", "3", "…
## $ `TAX CLASS AT PRESENT` <chr> "1", "1", "1", "1", "1", "1", "…
## $ BLOCK <dbl> 6359, 6360, 6364, 6367, 6371, 6…
## $ LOT <dbl> 70, 48, 74, 24, 19, 32, 65, 20,…
## $ `EASE-MENT` <lgl> NA, NA, NA, NA, NA, NA, NA, NA,…
## $ `BUILDING CLASS AT PRESENT` <chr> "S1", "A5", "A5", "A9", "A9", "…
## $ ADDRESS <chr> "8684 15TH AVENUE", "14 BAY 10T…
## $ `APARTMENT NUMBER` <chr> NA, NA, NA, NA, NA, NA, NA, NA,…
## $ `ZIP CODE` <dbl> 11228, 11228, 11214, 11214, 112…
## $ `RESIDENTIAL UNITS` <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1…
## $ `COMMERCIAL UNITS` <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `TOTAL UNITS` <dbl> 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1…
## $ `LAND SQUARE FEET` <dbl> 1933, 2513, 2492, 1571, 2320, 3…
## $ `GROSS SQUARE FEET` <dbl> 4080, 1428, 972, 1456, 1566, 22…
## $ `YEAR BUILT` <dbl> 1930, 1930, 1950, 1935, 1930, 1…
## $ `TAX CLASS AT TIME OF SALE` <chr> "1", "1", "1", "1", "1", "1", "…
## $ `BUILDING CLASS AT TIME OF SALE` <chr> "S1", "A5", "A5", "A9", "A9", "…
## $ `SALE PRICE` <dbl> 1300000, 849000, 0, 830000, 0, …
## $ `SALE DATE` <dttm> 2020-04-28, 2020-03-18, 2019-0…

The glimpse() function provides a user-friendly way to view the column names and data types for all columns, or variables, in the data frame. With this function, we are also able to view the first few observations in the data frame. This data frame has 20,185 observations, or property sales records. And there are 21 variables, or columns.

#data science tutorials #beginner #r #r tutorial #r tutorials #rstats #tidyverse #tutorial #tutorials

Marcus  Flatley

Marcus Flatley


Getting Started with R Markdown — Guide and Cheatsheet

In this blog post, we’ll look at how to use R Markdown. By the end, you’ll have the skills you need to produce a document or presentation using R Mardown, from scratch!

We’ll show you how to convert the default R Markdown document into a useful reference guide of your own. We encourage you to follow along by building out your own R Markdown guide, but if you prefer to just read along, that works, too!

R Markdown is an open-source tool for producing reproducible reports in R. It enables you to keep all of your code, results, plots, and writing in one place. R Markdown is particularly useful when you are producing a document for an audience that is interested in the results from your analysis, but not your code.

R Markdown is powerful because it can be used for data analysis and data science, collaborating with others, and communicating results to decision makers. With R Markdown, you have the option to export your work to numerous formats including PDF, Microsoft Word, a slideshow, or an HTML document for use in a website.

r markdown tips, tricks, and shortcuts

Turn your data analysis into pretty documents with R Markdown.

We’ll use the RStudio integrated development environment (IDE) to produce our R Markdown reference guide. If you’d like to learn more about RStudio, check out our list of 23 awesome RStudio tips and tricks!

Here at Dataquest, we love using R Markdown for coding in R and authoring content. In fact, we wrote this blog post in R Markdown! Also, learners on the Dataquest platform use R Markdown for completing their R projects.

We included fully-reproducible code examples in this blog post. When you’ve mastered the content in this post, check out our other blog post on R Markdown tips, tricks, and shortcuts.

Okay, let’s get started with building our very own R Markdown reference document!

R Markdown Guide and Cheatsheet: Quick Navigation

1. Install R Markdown

R Markdown is a free, open source tool that is installed like any other R package. Use the following command to install R Markdown:


Now that R Markdown is installed, open a new R Markdown file in RStudio by navigating to File > New File > R Markdown…. R Markdown files have the file extension “.Rmd”.

2. Default Output Format

When you open a new R Markdown file in RStudio, a pop-up window appears that prompts you to select output format to use for the document.

New Document

The default output format is HTML. With HTML, you can easily view it in a web browser.

We recommend selecting the default HTML setting for now — it can save you time! Why? Because compiling an HTML document is generally faster than generating a PDF or other format. When you near a finished product, you change the output to the format of your choosing and then make the final touches.

One final thing to note is that the title you give your document in the pop-up above is not the file name! Navigate to File > Save As.. to name, and save, the document.

#data science tutorials #beginner #r #r markdown #r tutorial #r tutorials #rstats #rstudio #tutorial #tutorials