0
0
Data Analysis Pythondata~10 mins

Report generation (notebooks to HTML/PDF) in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert a Jupyter notebook to HTML format.

Data Analysis Python
import nbconvert

html_exporter = nbconvert.[1]()
output = html_exporter.from_filename('report.ipynb')
Drag options to blanks, or click blank then click option'
AHTMLExporter
BPDFExporter
CMarkdownExporter
DLatexExporter
Attempts:
3 left
💡 Hint
Common Mistakes
Using PDFExporter instead of HTMLExporter.
Confusing MarkdownExporter with HTMLExporter.
2fill in blank
medium

Complete the code to save the HTML output to a file.

Data Analysis Python
with open('report.html', [1]) as f:
    f.write(output[0])
Drag options to blanks, or click blank then click option'
A'r'
B'rb'
C'a'
D'w'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' mode which is for reading.
Using 'a' mode which appends instead of overwriting.
3fill in blank
hard

Fix the error in the code to convert a notebook to PDF using nbconvert.

Data Analysis Python
import nbconvert

pdf_exporter = nbconvert.[1]()
output = pdf_exporter.from_filename('report.ipynb')
Drag options to blanks, or click blank then click option'
AHTMLExporter
BPDFExporter
CNotebookExporter
DSlidesExporter
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTMLExporter when PDF output is needed.
Using SlidesExporter which is for slide presentations.
4fill in blank
hard

Fill both blanks to create a PDF file from notebook content.

Data Analysis Python
with open('report.pdf', [1]) as f:
    f.write(output[[2]])
Drag options to blanks, or click blank then click option'
A'wb'
B'w'
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Opening the file in text mode 'w' for PDF output.
Writing the second element of output which is resources/metadata, not PDF data.
5fill in blank
hard

Fill all three blanks to convert a notebook to HTML and save it with nbconvert.

Data Analysis Python
from nbconvert import [1]

exporter = [2]()
body, resources = exporter.from_filename('analysis.ipynb')

with open('analysis.html', [3]) as f:
    f.write(body)
Drag options to blanks, or click blank then click option'
AHTMLExporter
B'w'
Cnbconvert
DPDFExporter
Attempts:
3 left
💡 Hint
Common Mistakes
Importing PDFExporter when HTML output is needed.
Opening the file in binary mode for HTML output.