Reference cells
Reference cells from Python.
In Quadratic, reference individual cells from Python for single values or reference a range of cells for multiple values.
Referencing individual cells
To reference an individual cell, use the global function cell
(or c
for short) which returns the cell value.
You can reference cells and use them directly in a Pythonic fashion.
Any time cells dependent on other cells update the dependent cell will also update. This means your code will execute in one cell if it is dependent on another. This is the behavior you want in almost all situations, including user inputs in the sheet that cause calculation in a Python cell.
Referencing a range of cells
To reference a range of cells, use the global function cells
which returns a Pandas DataFrame.
If the first row of cells is a header, you should set first_row_header
as an argument. This makes the first row of your DataFrame the column names, otherwise will default to integer column names as 0, 1, 2, 3, etc.
Use first_row_header when you have column names that you want as the header of the DataFrame. This should be used commonly. You can tell when a column name should be a header when the column name describes the data below.
As an example, this code references a table of expenses, filters it based on a user-specified column, and returns the resulting DataFrame to the spreadsheet.
Alternatively, slicing syntax works for selecting a range of cells (returns a Pandas DataFrame).
Referencing another sheet
To reference another sheet's cells or range of cells use the following:
Relative references
Reference cells relative to the cell you're currently in with relative cell references in Python.
Get position of current cell
Keyword pos()
returns a tuple of the (x, y)
coordinates of the current cell.
Reference values in relative cells
Reference the values of cells relative the current position.
Last updated