Return data to the sheet
Return the data from your Python code to the spreadsheet.
Quadratic is built to seamlessly integrate Python to the spreadsheet. This means being able to manipulate data in code and very simply output that data into the sheet.
By default, the last line of code is output to the spreadsheet. This should be one of the four basic types:
Single value: for displaying the single number result of a computation
List of values: for displaying a list of values from a computation
DataFrame: for displaying the workhorse data type of Quadratic
Chart: for displaying Plotly charts in Quadratic
Function outputs: return the results of functions to the sheet
You can expect to primarily use DataFrames as Quadratic is heavily built around Pandas DataFrames due to widespread Pandas adoption in almost all data science communities!
1. Single Value
Note the simplest possible example, where we set x = 5
and then return x
to the spreadsheet by placing x
in the last line of code.
2. List of values
Lists can be returned directly to the sheet. They'll be returned value by value into corresponding cells as you can see below.
3. DataFrame
You can return your DataFrames directly to the sheet by putting the DataFrame's variable name as the last line of code.
Note that if your DataFrame has an index it will not be returned to the sheet. If you want to return the index to the sheet use the following code:
An example of when this is necessary is any time you use the describe() method in Pandas. This creates an index so you'll need to use reset_index() if you want to correctly display the index in the sheet when you return the DataFrame.
4. Charts
Build your chart and return it to the spreadsheet by using the fig
variable name or .show()
5. Function outputs
You can not use the return
keyword to return data to the sheet, as that keyword only works inside of Python functions. Here is an example of using a Python function to return data to the sheet.
Last updated