dataframe.create_dataframe

create_dataframe(seed, keys, width, default_value=None)

Create a pre-sized Dataframe with specified shape and initial values.

Factory function for creating Dataframes with predetermined dimensions. Useful when you know the final structure upfront and want to initialize all cells with specific patterns or values.

Parameters

Name Type Description Default
seed Any Initial values to populate the Dataframe. Can be: - Scalar (Any): Same value repeated across all cells - list: Values applied to all rows, padded with default_value if shorter - dict: Per-row initialization (supports mixed list/scalar values per key) - Dataframe: Copy values from existing Dataframe - None: Fill all cells with default_value required
keys list[Hashable] List of keys (row labels) for the Dataframe. These become the symbol keys in LaTeX output when used with show_eqn(). required
width int Number of columns in the Dataframe (number of cells per row). required
default_value Any Value used to fill missing entries when seed doesn’t cover all cells. Defaults to None. None

Returns

Name Type Description
Dataframe New Dataframe with specified shape (len(keys), width) and initialized values.

Examples

from keecas import symbols
from keecas.dataframe import create_dataframe

# Create empty structure
x, y = symbols(r"x, y")
df = create_dataframe(None, [x, y], width=3)
df
Dataframe({x: [None, None, None], y: [None, None, None]}, shape=(2, 3))
# Initialize with scalar seed
df = create_dataframe(0, [x, y], width=3)
df

\(\displaystyle \left\{ x : \left[ 0, \ 0, \ 0\right], \ y : \left[ 0, \ 0, \ 0\right]\right\}\)

# Initialize with list seed (same for all rows)
df = create_dataframe([1, 2], [x, y], width=2)
df

\(\displaystyle \left\{ x : \left[ 1, \ 2\right], \ y : \left[ 1, \ 2\right]\right\}\)

# Per-row initialization with dict
df = create_dataframe(
    {x: [10, 20], y: 99},  # x gets list, y gets scalar
    [x, y],
    width=2,
    default_value=-1
)
df

\(\displaystyle \left\{ x : \left[ 10, \ 20\right], \ y : \left[ 99, \ 99\right]\right\}\)

See Also

  • Dataframe: Main class with initialization options
  • show_eqn: Function that uses Dataframe for rendering

Notes

  • All rows guaranteed to have exactly ‘width’ columns
  • List seed applies same list to all rows
  • Dict seed allows per-row customization
  • Dataframe seed handled automatically (dict subclass)
  • Useful for pre-allocating structure before filling with computed values
  • No filler parameter needed - all data constructed at correct width