From the course: Testing Python Data Science Code

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Refactoring code

Refactoring code

- [Instructor] One of the options you have for testing Jupyter notebooks is to refactor the code. Refactoring means reorganizing the code or restructuring it. Let's see an example of calculating the running speed. So here is my initial notebook. This is the before notebook. So we have a cell for loading the data, cell for calculating the speed, and then calculating time and displaying the average and placing it to output. What I'm going to do is convert several of these cells to functions. You can start that by exporting the notebook to a Python file, either with the nbconvert utility or from JupyterLab or Jupyter Notebooks. And now you can create tracklib. And here we have a function to load the CSV, to calculate the distance, and to calculate the running speed of a DataFrame. And our notebook now is much, much simpler. It contains one cell to import our tracklib and another one to run the actual computation.…

Contents