Jupyter Notebook lets you write and run code step-by-step. It helps you see results right away and explain your work clearly.
When you want to explore data interactively and see charts immediately.
When you need to explain your data analysis with code and notes together.
When you want to test small pieces of code before building a bigger program.
When you want to share your work with others in an easy-to-read format.
When you want to combine code, text, and images in one place.
Syntax
Data Analysis Python
1. Install Jupyter with: pip install notebook
2. Start Jupyter Notebook by running: jupyter notebook
3. Create a new notebook and write Python code in cells.
4. Run a cell by pressing Shift + Enter.
You need Python installed before installing Jupyter Notebook.
Each cell can contain code or text (Markdown).
Examples
Write Python code in a cell and run it to see output below.
Data Analysis Python
# This is a code cellprint('Hello, Jupyter!')
Use Markdown cells to add explanations or titles.
Data Analysis Python
## This is a Markdown cell# You can write notes like this.
Run calculations and see results immediately.
Data Analysis Python
# Run math calculations2 + 3 * 4
Sample Program
This code creates a small table of fruits and their counts, shows the table, and draws a bar chart.
Data Analysis Python
# Sample Jupyter Notebook codeimport pandas as pd
import matplotlib.pyplot as plt
# Create a simple data table
data = {'Fruits': ['Apple', 'Banana', 'Cherry'], 'Count': [10, 15, 7]}
df = pd.DataFrame(data)
# Show the table
display(df)
# Plot a bar chart
plt.bar(df['Fruits'], df['Count'])
plt.title('Fruit Counts')
plt.xlabel('Fruit')
plt.ylabel('Count')
plt.show()
OutputSuccess
Important Notes
Use Shift + Enter to run a cell and move to the next one.
Save your notebook often to avoid losing work.
You can export notebooks as HTML or PDF to share with others.
Summary
Jupyter Notebook helps you write and run code step-by-step.
You can mix code, text, and visuals in one place.
It is great for learning, exploring data, and sharing results.
Practice
(1/5)
1. What is the main purpose of using a Jupyter Notebook in data science?
easy
A. To compile large software projects
B. To write and run code step-by-step with explanations
C. To create websites with HTML and CSS
D. To manage databases and run SQL queries
Solution
Step 1: Understand Jupyter Notebook's role
Jupyter Notebook allows running code in small pieces, making it easy to test and explain.
Step 2: Compare with other options
Options A, B, and D describe other tools or tasks not related to Jupyter Notebook's main use.
Final Answer:
To write and run code step-by-step with explanations -> Option B
Quick Check:
Jupyter Notebook = step-by-step code and explanations [OK]
Hint: Remember: Jupyter mixes code and notes for easy learning [OK]
Common Mistakes:
Confusing Jupyter with web development tools
Thinking Jupyter compiles code like an IDE
Assuming Jupyter manages databases directly
2. Which of the following is the correct way to start a Jupyter Notebook from the command line?
easy
A. jupyter notebook
B. start notebook
C. run jupyter
D. open notebook
Solution
Step 1: Recall the command to launch Jupyter
The official command to start Jupyter Notebook is jupyter notebook.
Step 2: Check other options
Options B, C, and D are not valid commands and will cause errors.
Final Answer:
jupyter notebook -> Option A
Quick Check:
Start Jupyter with 'jupyter notebook' command [OK]
Hint: Use 'jupyter notebook' exactly to launch [OK]
Common Mistakes:
Typing incomplete or incorrect commands
Using 'run' or 'open' instead of 'jupyter notebook'
Confusing with other software commands
3. Consider this Jupyter Notebook cell code:
for i in range(3):
print(i)
What will be the output when you run this cell?
medium
A. Error: Indentation required
B. 0 1 2
C. [0, 1, 2]
D. 0
1
2
Solution
Step 1: Understand the loop and print behavior
The loop runs for i = 0, 1, 2. Each print outputs i on a new line.
Step 2: Determine output format
Print statements in Python output each value on a separate line, so output is '0\n1\n2'.
Final Answer:
0\n1\n2 -> Option D
Quick Check:
Print in loop outputs each value on new line [OK]
Hint: Remember print adds a new line after each call [OK]
Common Mistakes:
Thinking print outputs values on the same line
Confusing list output with print output
Assuming syntax error due to indentation
4. You run this code in a Jupyter Notebook cell:
for i in range(3)
print(i)
What is the error and how do you fix it?
medium
A. SyntaxError: Missing colon after for loop; add ':' after range(3)
B. IndentationError: Indent print less
C. NameError: 'i' is not defined
D. No error; code runs fine
Solution
Step 1: Identify syntax error in for loop
The for loop is missing a colon ':' at the end of the line, which is required in Python.
Step 2: Fix the syntax by adding colon
Adding ':' after range(3) fixes the syntax and allows the code to run.
Final Answer:
SyntaxError: Missing colon after for loop; add ':' after range(3) -> Option A
Quick Check:
For loops need ':' at end [OK]
Hint: Always put ':' after for loops and if statements [OK]
Common Mistakes:
Forgetting colon at end of for loop
Misunderstanding indentation errors
Assuming variable 'i' is undefined
5. You want to share your Jupyter Notebook with a friend who does not have Python installed. Which option lets your friend view your notebook easily?
hard
A. Print the notebook and mail the paper copy
B. Send the .ipynb file and ask them to install Python
C. Export the notebook as HTML and send the file
D. Convert notebook to .exe file and send
Solution
Step 1: Understand sharing options for Jupyter Notebooks
Exporting as HTML creates a file that can be opened in any web browser without Python.
Step 2: Evaluate other options
A is impractical for interactive content, B requires Python installation, C is not a standard conversion.
Final Answer:
Export the notebook as HTML and send the file -> Option C
Quick Check:
HTML export = easy sharing without Python [OK]
Hint: Export as HTML to share without Python installed [OK]
Common Mistakes:
Assuming .ipynb files open without Python
Trying to convert notebook to executable
Ignoring interactive features by printing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.