Many languages pride themselves in having “batteries included”, meaning everything needed to use the language is provided. While we agree with this philosophy, we also want to minimize the complexity of large frameworks that come with languages like Python and Java. Having fewer choices means that it’s easier to learn, and our goal is to get you productive as quickly as possible. Consequently, Pez only supports a handful of data structures natively.

*Before we talk about data structures, be sure you understand the basic types in pez.*

## Vectors

Vectors represent an ordered collection of things. If you are coming from Excel, you can think of a vector as being a contiguous range of cells. The elements of a vector can all be of the same type, such as a sequence of integers.

1 |
x = [1,2,3,4] |

They can also be heterogeneous like a set.

1 |
z = [1,"two",3.0,false] |

Realistically, most of your vectors will be homogeneous, making them easier to work with. For numeric vectors, mixed algebraic operations work just like in linear algebra, where scalars are applied to all elements of a vector.

1 2 3 4 5 6 |
!pez [1,2,3,4] * 2 1 2 2 4 3 6 4 8 dtype: int64 |

## Data Frames

A data frame is a tabular data structure composed of many vectors. You can think of a data frame as being a table where each column is a vector. In Excel, a data frame is similar to a grid of cells. Thus it’s easy to see why all the vectors comprising the grid have equal length.

1 2 3 4 5 6 7 8 9 10 11 12 13 |
!pez y = [5,6,7,8] 1 5 2 6 3 7 4 8 dtype: int64 !pez d = { x,y } X1 X2 1 1 5 2 2 6 3 3 7 4 4 8 |

In the output, the left most column is the index. This tells you what index to use to extract an element from the data frame. The top row contains the column headers. If no information is provided, then it defaults to “X” followed by an index number. If you don’t like the default names, you can name them yourself when creating the data frame. Just like a table header, this can add extra information that is useful for someone using this object.

1 2 3 4 5 6 |
!pez d = { a=x, b=y } a b 1 1 5 2 2 6 3 3 7 4 4 8 |

## Indices

Both vectors and data frames support indices. When using a literal, simply assign the @index attribute within the literal. For a vector, this looks like

1 2 3 4 5 6 |
!pez y = [5,6,7,8, @index=['a','b','c','d']] a 5 b 6 c 7 d 8 dtype: int64 |

Element can then be accessed via ordinal index or label.

1 2 3 4 5 6 |
!pez y['b'] b 6 dtype: int64 !pez y[2] b 6 dtype: int64 |