Welcome to QTM 151!

print("Welcome to QTM 151!")

x = 5
y = 10
z = x + y
print(z)
Welcome to QTM 151!
15

This is a Jupyter Notebook. You can write text, equations, and code in this notebook.

Using pandas.DataFrame.to_markdown()

# If necessary, install pandas and tabulate
# You should have the pandas library installed if you installed Anaconda, 
# but if you do not, you can install both with the following terminal command:
# conda install pandas tabulate

# Import pandas
import pandas as pd
from tabulate import tabulate

# Create a sample DataFrame
data = {
    "Name": ["Alice", "Bob", "Charlie"],
    "Age": [25, 30, 35],
    "City": ["New York", "London", "Paris"]
}
df = pd.DataFrame(data)

# Print the DataFrame as Markdown, no index (row numbers)
markdown_table = df.to_markdown(index=False)
print(markdown_table)
| Name    |   Age | City     |
|:--------|------:|:---------|
| Alice   |    25 | New York |
| Bob     |    30 | London   |
| Charlie |    35 | Paris    |
# You should also have the IPython package installed if you installed Anaconda
# If not, you can install it with
# conda install ipython

# Import the Markdown display class. 
# This is what allows us to display Markdown in Jupyter Notebooks 
from IPython.display import display, Markdown

# Display the Markdown table
display(Markdown(markdown_table))
Name Age City
Alice 25 New York
Bob 30 London
Charlie 35 Paris
# Customising the Markdown table using the to_markdown() method
markdown_table = df.to_markdown(
    index=False,  # Don't include index
    tablefmt="pipe",  # Use pipe format
    floatfmt=".2f",  # Format floats to 2 decimal places
    headers=["Name", "Age (Years)", "City"],  # Custom headers
    colalign=("left", "center", "right")  # Align columns
)
display(Markdown(markdown_table))
Name Age (Years) City
Alice 25 New York
Bob 30 London
Charlie 35 Paris
# Using the tabulate library to create a Markdown table
import pandas as pd
from IPython.display import display, Markdown
from tabulate import tabulate

# Create a sample DataFrame
data = {
    "Product": ["Laptop", "Smartphone", "Tablet"],
    "Price": [999.99, 599.50, 299.75],
    "Stock": [50, 100, 75],
    "Rating": [4.5, 4.8, 4.2]
}
df = pd.DataFrame(data)

# Create a formatted Markdown table
# The floatfmt parameter formats columns as floats with 2 decimal places,
# integers, and floats with 1 decimal place, respectively
markdown_table = tabulate(
    df,
    headers=["Product Name", "Price ($)", "Stock Quantity", "Customer Rating"],
    tablefmt="pipe", # Format as Markdown table
    floatfmt=(".2f", ".2f", "d", ".1f"),
    showindex=False, # Don't show the index (row numbers)
    numalign="right", # Align numbers to the right
    stralign="left" # Align strings (text, first column) to the left
)

# Display the table in the notebook
display(Markdown("### Product Inventory Summary"))
display(Markdown(markdown_table))

Product Inventory Summary

Product Name Price ($) Stock Quantity Customer Rating
Laptop 999.99 50 4.5
Smartphone 599.50 100 4.8
Tablet 299.75 75 4.2

Equations

\[\sigma =\sqrt{\frac{\sum{i=1}ˆ{N}(xi -\mu)ˆ2}{N}}\]

(Check https://www.overleaf.com/learn/latex/List_of_Greek_letters_and_math_symbols)

Example of Footnotes in Jupyter Notebook

You can include footnotes in your Jupyter Notebook using Markdown syntax. For example, this is a sentence with a footnote.1

Here is another sentence with a different footnote.2

Back to top

Footnotes

  1. This is the first footnote.↩︎

  2. This is the second footnote.↩︎