0
0
Data Analysis Pythondata~10 mins

Profiling with line_profiler 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 import the line_profiler module.

Data Analysis Python
import [1]
Drag options to blanks, or click blank then click option'
AcProfile
Bline_profiler
Ctimeit
Dprofile
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'cProfile' instead of 'line_profiler'.
Using 'profile' which is a decorator but not the module name.
2fill in blank
medium

Complete the code to create a LineProfiler object.

Data Analysis Python
profiler = [1]()
Drag options to blanks, or click blank then click option'
ALineProfiler
BProfile
CcProfile
DTimer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Profile' which is from a different module.
Using 'Timer' which is unrelated.
3fill in blank
hard

Fix the error in the code to add a function to the profiler.

Data Analysis Python
profiler.[1](my_function)
Drag options to blanks, or click blank then click option'
Aadd_function
Brun
Cadd_function_to_profile
Dadd_func
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' which executes code but does not add functions.
Using 'add_func' which is not a valid method.
4fill in blank
hard

Fill both blanks to run the profiler on a function and print the stats.

Data Analysis Python
profiler.[1](my_function)
profiler.[2]()
Drag options to blanks, or click blank then click option'
Arun
Bprint_stats
Cstart
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' and 'stop' which are not methods of LineProfiler.
Using 'run' twice or 'print_stats' first.
5fill in blank
hard

Fill all three blanks to decorate a function, run it, and print profiling results.

Data Analysis Python
@profiler.[1]
def my_function():
    total = 0
    for i in range(1000):
        total += i
    return total

my_function()
profiler.[2](my_function)
profiler.[3]()
Drag options to blanks, or click blank then click option'
Aprofile
Badd_function
Cprint_stats
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' as decorator instead of 'profile'.
Not adding the function before printing stats.