Quadratic
Search…
⌃K
Links

Pandas DataFrame

Returning a Pandas DataFrame to the Grid

The following code creates a DataFrame of 15 rows, by 4 columns filled with random numbers between 0 and 100. It is the last expression, so it is returned to the Grid.
# pandas and numpy are preloaded by default!
import pandas as pd
import numpy as np
# using numpy's randint, return df to Grid
pd.DataFrame(np.random.randint(
0,
100,
size=(15, 4),
))
Returning a DataFame to the Grid

Referencing a Range of Cells

To reference a range of cells use cells((0, 0), (10, 10)).
This returns a Pandas DataFrame.
If the first row of cells is a header, you can set first_row_header as an argument.
cells((2, 2), (7, 52), first_row_header=True)
This will tell Pandas to use the first row as the header.
For Example: In this grid we are taking a list of expenses, and filtering it to a single category - using a DataFrame - and returning it to the Grid.
# pull the full expenses table in as a DataFrame
expenses_table = cells((2, 2), (7, 52), first_row_header=True)
category = cell(10, 0) # category = "Gas"
# filter the full expenses table to "Gas" category, return the resulting DF
expenses_table[expenses_table["Category"] == category]
Example of Filtering a Pandas DataFrame and returning it back to the Grid