How to... format Python and SQL cells?
As standard, cells use Python as the default language for notebooks. You can override the default language in a cell by running the shortcut Cmd+Shift+F (you must be attached to a running cluster), or by clicking the language button and selecting a language from the dropdown menu.
Alternatively, you can use magic !
To change the language of a single cell use so called magic commands: %<language>
. There are four supported magic languages which are: %python
, %r
, %scala
, and %sql
.
N.b. when committing mixed language code to GitLab, you will notice that Markdown or Magic commands are commented out as shown below. This is because GitLab saves Databricks notebooks as .py files by default and does not support multiple programming languages per file. Read more about this here.
See Also: