Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Introduction to Jupyter and Python


This lab introduces two tools that extend what you can do with data:

  • Jupyter Notebooks, the interactive environment you’re in right now

  • Python, a programming language widely used for data analysis, web development, and automation

By the end, you’ll be able to load a dataset, do basic calculations on it, and make a chart using Python.

What you’ll practice:

  • Navigating and running cells in a Jupyter Notebook

  • Writing basic Python: variables, data types, and lists

  • Loading and exploring a dataset using pandas

  • Creating a simple chart from data

How to run a cell: Click on any code cell below and press Shift + Enter (or click the Run button in the toolbar). The result appears directly below the cell.


Setup: Install and Import Packages

Before we start, run the cell below. It checks whether the required Python packages are already installed and installs any that are missing. This only needs to run once per session.

Run this cell first. Everything else in the lab depends on it.


Section 1: Your First Cell

Jupyter Notebooks are made of cells. There are two main types:

  • Markdown cells (like this one) display formatted text, images, and instructions

  • Code cells (gray background) contain Python code that you can run

Let’s run your first code cell. Press Shift + Enter on the cell below.

You should see Welcome to CIS 13! appear below the cell. The number in the brackets [1] on the left tells you the order cells were run.

TO-DO 1: Your first print statement

In the cell below, replace the ... with a print() statement that displays your own name.

Example: print("Alex Rivera")


Section 2: Python as a Calculator

The simplest thing Python can do is math. Just like typing a formula in Excel’s formula bar, you can type an expression and Python evaluates it.

Excel formulaPython equivalent
=5+35 + 3
=10*210 * 2
=9/39 / 3
=2^82 ** 8

Run the demo cell below to see Python do some arithmetic:

TO-DO 2: Calculate a total cost

A customer buys 15 notebooks at $2.49 each and 4 pens at $0.99 each.

In the cell below, write a Python expression that calculates the total cost. Replace ... with your expression.


Section 3: Variables

In Excel, you store a value in a cell (like cell B4). In Python, you store a value in a variable, which is a named container you create yourself.

Excel:   B4 = 49.99
Python:  price = 49.99

Variables make your code readable and reusable. Run the demo below:

Python has different data types for different kinds of values:

TypeExampleWhat it holds
int42Whole numbers
float29.99Decimal numbers
str"Wireless Mouse"Text (always in quotes)
boolTrue / FalseYes/No values

You can check a variable’s type with the built-in type() function:

TO-DO 3: Create your own variables

Imagine you work at a campus bookstore. Fill in the ... placeholders to create variables for a product of your choice, then print a summary line.

Question 1

In Excel, if you change a value in cell B4, any formula that references B4 automatically updates. In Python, if you update a variable after using it in a calculation, does the calculation update automatically? How would you test this?

Type your answer here.


Section 4: Lists

A single variable holds one value. A list holds many values in order. Think of it as one column from an Excel spreadsheet.

Excel column A:   Python list:
  Laptop            products = ["Laptop", "Keyboard", "Monitor", "Webcam"]
  Keyboard
  Monitor
  Webcam

Run the demo:

Notice that Python starts counting at 0, not 1. So products[0] is "Laptop", and products[1] is "Keyboard".

TO-DO 4: Build a list and find the total

A store sold the following quantities of four items this week: 12, 5, 30, 8.

Create a list called weekly_sales, then use Python’s built-in sum() and max() functions to find the total and the highest single sale.

Question 2

Excel’s SUM() function and Python’s sum() function both add up a range of numbers. What is one advantage of using Python lists over an Excel column for storing data? What is one advantage Excel has?

Type your answer here.


Section 5: Introducing pandas

So far we’ve worked with individual values and simple lists. But real-world data has rows and columns, just like an Excel spreadsheet.

pandas is a Python library for working with tabular data. It gives us a DataFrame, which is an object that works like a spreadsheet inside Python.

Excel Workbook ≈ pandas DataFrame
Excel Row      ≈ DataFrame row
Excel Column   ≈ DataFrame Series (column)
=SUM(B:B)      ≈ df["Units Sold"].sum()
=AVERAGE(B:B)  ≈ df["Units Sold"].mean()

Run the cell below to load pandas and a small dataset we’ll use for the rest of the lab:

Viewing the data

Just like scrolling through an Excel spreadsheet, pandas gives you several ways to view your data:

Selecting a column

To select a single column, use the column name in square brackets, the same way you’d click a column header in Excel:

Creating a new column

In Excel, you’d write a formula like =B2*C2 and drag it down. In pandas, you define the whole column at once and it applies to every row automatically:

TO-DO 5: Add a Discount Price column

The store is running a 10% off promotion. Add a new column called "Discounted_Price" that shows each product’s unit price after the discount.

Hint: 10% off means multiply by 0.90.

Question 3

In Excel, applying a formula like =B2*0.90 to 1,000 rows means dragging the formula down (or double-clicking). In pandas, you write one line and it applies to all rows automatically. Why might this matter when working with large datasets in a business setting?

Type your answer here.


Section 6: Filtering Data

In Excel, you use Filters to show only rows that meet a condition. In pandas, you write a condition directly:


Section 7: Your First Chart

pandas can create charts directly from your data, similar to Excel’s Insert Chart feature. We’ll use matplotlib, the standard Python charting library.

TO-DO 6: Chart the Revenue column

Create a bar chart showing Revenue (not Units Sold) for each product. Copy the demo above and change:

  1. The column on the y-axis from "Units_Sold" to "Revenue"

  2. The chart title to something appropriate

  3. The bar color to any color you like (try "coral", "seagreen", or "mediumpurple")

Question 4

Look at your Revenue chart compared to the Units Sold chart. Are the rankings the same? Which product generates the most revenue even though it might not sell the most units? What does this tell you as a store manager?

Type your answer here.

Question 5

This lab used a small dataset with 8 rows. Imagine you work for a company with 50,000 product transactions per month. List two things Python/pandas could do with that data that would be difficult or impractical to do manually in Excel.

Type your answer here.


That’s it!

Here’s a quick recap of what you worked through:

TopicWhat you tried
Jupyter NotebooksRunning code cells, mixing code and text
Python basicsVariables, data types, lists, arithmetic
pandasLoading data, selecting columns, creating new columns, filtering rows
matplotlibCreating and customizing a bar chart

These tools come up again in the databases and systems topics later in CIS 13, so anything you picked up here will be useful.


CIS 13 · El Camino College · Prof. Hac Le