Built-in Python Code Window

The code window on the right side of all Row Zero workbooks is a Python development environment. It works like a code cell in a Jupyter notebook.

The window enables writing custom Python functions that are referenced in the spreadsheet and importing popular Python libraries. Code written in the code window cannot reference or modify data in the spreadsheet. You can create helper functions that perform complex computations or pull data through python libraries, which can all be used and referenced in the spreadsheet. The code window can be executed by clicking the 'RUN' button or hitting shift+enter.

Custom functions

Custom Python functions can be defined in the code window. Once defined, they can be used in the spreadsheet by calling the function after an '=.'

# Define a custom function
def foo(x):
    return "Hello " + str(x)

# Type '=foo(x)' in a spreadsheet cell and pass in an argument, like A1.

Import Python Packages

Popular Python packages, like scipy, pandas, and others can be imported into the workbook with the normal python syntax of 'import pandas as pd.' If an attempt to import a module returns a 'modulenotfound' error, the module is not yet supported. See supported Python packages below. Requests for additional Python module/package support can be sent to [email protected].

# Example import Python packages
import pandas as pd
import scipy as sp

Supported Python Packages

Python to Spreadsheet Data Mapping

Spreadsheet types are converted (marshalled) to/from Python as follows:

Spreadsheet Type      Python Type

text                  str
number                float
date                  datetime.date
datetime              datetime.datetime
struct                dict
Data Table            polars.dataframe.frame.DataFrame

Spreadsheet text variables support Python's string index/slicing syntax (e.g. ="my*string"[0:3] returns "my*")

Marshalling is bidirectional. For example, you can define a Python function that returns a pandas DataFrame and this will be represented in the spreadsheet as a Data Table, which offers sorting and filtering capabilities.

Range references (e.g. A1:A100) are converted to Python iterables. So if you want to sum the values in a range, define your python function like this:

def foo(range_ref):
     sum = 0
     for x in range_ref:
          sum += x
     return sum

# For this example, type '=foo(A1:A100)' in a spreadsheet cell and it will sum A1:A100 .

Important Notes

  • Functions defined in Python are available as formulas in the spreadsheet. Note that these Python functions do not autocomplete as you start to type them.
  • Spreadsheet data cannot be referenced in the code window and you cannot modify the spreadsheet from Python.

Python Examples

Here are a few posts that walk through examples of using Python in Row Zero: