The All of Us Researcher Workbench team has created several code snippets to execute functions that we think will be commonly used by researchers. A code snippet is a block of code that performs a specific function or set of functions on your data. Additional snippets will be available as time goes on and we learn more about the functions that workbench users commonly perform on All of Us data. For more information on what code snippets are currently available in the Researcher Workbench, see the following articles in our User Support Hub: Code Snippets Catalog [Python] and Code Snippets Catalog [R].
Where do I find code snippets?
Within a notebook navigate to “Snippet” in the menu bar…
You will find sets of All of Us specific snippets that have been created to work specifically with All of Us data as well as standard snippets in common packages such as NumPy, pandas, and Matplotlib.
- First run the “(1) Setup” snippet.
- Hover over the snippet name to see a preview of the code.
- Select an empty cell in your notebook and then click on the setup snippet.
- The code will appear in the selected cell.
- Run the cell to execute the code.
How do I use a snippet?
After running the "Setup" snippet, you can select and run another snippet.
For example, we will run the summarize_a_dataframe snippet from the "Basic operations" menu.
The snippets typically have a few parts.
- Text prefaced by a # symbol in blue/green color is explanatory text and not part of the executed code.
- There will be part of the code that needs to be customized to work on your dataframe. This will be found in the first cell(s) of your notebook after you export a dataset.
Check out our video on Notebooks and Code Snippets for more information on using code snippets in Jupyter Notebooks.