Post

Data Frames, Columns, and Expressions

A survey response time is meaningful only when we know which submission it describes. If one person submits twice, the participant identifier alone cannot distinguish those measurements. We therefore need a structure that associates each duration with both its submission and its participant. In this chapter, we build that structure as a data frame and calculate with its columns. We examine how R and Python locate column values and evaluate calculations, then compare results that describe individual submissions with results that summarize the submissions together.

5.1 Observations, variables, and identifiers

To calculate with several response times together, we can organize them in a data frame alongside their submission and participant identifiers. A data frame is a rectangular table. We will build one in R and Python from the three constructed responses in Table 5.1.

Table 5.1. Duration in seconds for each of three constructed survey responses.

response_idparticipant_idseconds
r1p130
r2p190
r3p2120

Each submitted form is an observation, a case for which values are recorded. Because there is one row per form, the form is the row unit. Each column records a variable, a characteristic such as the form’s duration. The two forms from p1 occupy separate rows so that both response times can be represented.

Loading tidyverse makes tibble() available for building a tibble, a form of data frame. Each argument to tibble() names a column and gives its values in response order. A tibble stores its columns as a list, so length(responses) counts columns. nrow(responses) counts rows, one per response. Both counts happen to be 3. The display omits the package startup message.

1
2
3
4
5
6
7
8
9
10
11
library(tidyverse)
responses <- tibble(
  response_id = c("r1", "r2", "r3"),
  participant_id = c("p1", "p1", "p2"),
  seconds = c(30, 90, 120)
)
responses
typeof(responses)
length(responses)
nrow(responses)
names(responses)
1
2
3
4
5
6
7
8
9
10
# A tibble: 3 × 3
  response_id participant_id seconds
  <chr>       <chr>            <dbl>
1 r1          p1                  30
2 r2          p1                  90
3 r3          p2                 120
[1] "list"
[1] 3
[1] 3
[1] "response_id"    "participant_id" "seconds"       

The display reports three rows and three columns, with <chr> for character columns and <dbl> for double. In the first two rows, p1 is associated with different responses and durations. Participant ID cannot tell these two responses apart. response_id is unique across these records, so it is a candidate key, a column that could identify each row.

import polars as pl makes pl.DataFrame() available. In the dictionary passed to pl.DataFrame(), each key names a column and the corresponding list contains its values. The result is a DataFrame with columns of equal length, each with one type. shape gives the row and column counts, and columns gives the names.

1
2
3
4
5
6
7
8
9
10
11
12
13
import polars as pl

responses = pl.DataFrame(
    {
        "response_id": ["r1", "r2", "r3"],
        "participant_id": ["p1", "p1", "p2"],
        "seconds": [30, 90, 120],
    }
)
responses
type(responses)
responses.shape
responses.columns
1
2
3
4
5
6
7
8
9
10
11
12
13
shape: (3, 3)
┌─────────────┬────────────────┬─────────┐
│ response_id ┆ participant_id ┆ seconds │
│ ---         ┆ ---            ┆ ---     │
│ str         ┆ str            ┆ i64     │
╞═════════════╪════════════════╪═════════╡
│ r1          ┆ p1             ┆ 30      │
│ r2          ┆ p1             ┆ 90      │
│ r3          ┆ p2             ┆ 120     │
└─────────────┴────────────────┴─────────┘
<class 'polars.dataframe.frame.DataFrame'>
(3, 3)
['response_id', 'participant_id', 'seconds']

The shape (3, 3) means three rows and three columns. The header shows text as str and 64-bit integer seconds as i64. Positions start at 0, so .row(0) and .row(1) return p1’s two submissions as tuples.

1
2
responses.row(0)
responses.row(1)
1
2
('r1', 'p1', 30)
('r2', 'p1', 90)

Both tuples contain p1, so the participant ID cannot distinguish these responses. The tuples pair r1 with 30 seconds and r2 with 90 seconds. Each response_id occurs once in this table, making it a candidate key, a column that can identify each row.

To check p2’s 120-second response again, we could currently select the third row. But sorting complete rows from longest to shortest duration would put r3 first and r1 third. Selecting the third row would then retrieve a different submission. Selecting the row whose response_id is r3 would retrieve p2’s response in either order. The identifier lets us refer to the response without relying on its position in the table.

5.2 Columns, types, and schemas

Suppose the duration of r3 was not recorded. We still know that p2 submitted it. How can we record the missing time and still calculate with the other two durations? The table with_missing represents this case. The original responses has all three measurements.

The missing time must occupy a position in the duration column so that each value corresponds to the correct response. We will inspect that column both as a collection of values and as a one-column table, checking its type and length in each form.

In with_missing, NA marks the missing duration. with_missing$seconds extracts the numeric column as a vector. Adding [3] selects its third element. The lengths show whether the missing measurement still occupies a position in the column.

1
2
3
4
5
6
7
8
9
10
11
with_missing <- tibble(
  response_id = c("r1", "r2", "r3"),
  participant_id = c("p1", "p1", "p2"),
  seconds = c(30, 90, NA)
)
with_missing$seconds
length(with_missing$seconds)
typeof(with_missing$seconds)
with_missing$seconds[3]
length(with_missing$seconds[3])
nrow(with_missing)
1
2
3
4
5
6
[1] 30 90 NA
[1] 3
[1] "double"
[1] NA
[1] 1
[1] 3

The duration column is a double vector of length three. Selecting its third position returns a length-one vector containing NA. Even with only two measured durations, with_missing still has one row for each of the three responses.

Single brackets with a column name return the column inside a tibble. with_missing["seconds"] contains the same measurements as the extracted vector, but has rows and a named column. dim() reports its dimensions and typeof() shows that it is stored as a list.

1
2
3
with_missing["seconds"]
dim(with_missing["seconds"])
typeof(with_missing["seconds"])
1
2
3
4
5
6
7
8
# A tibble: 3 × 1
  seconds
    <dbl>
1      30
2      90
3      NA
[1] 3 1
[1] "list"

A schema lists the column names and their types. glimpse() shows this information with sample values, while lengths() reports the size of each column. Here every column has three positions, so the table is rectangular. The numeric NA occupies one of those positions without changing the duration column to text.

1
2
glimpse(with_missing)
lengths(with_missing)
1
2
3
4
5
6
7
Rows: 3
Columns: 3
$ response_id    <chr> "r1", "r2", "r3"
$ participant_id <chr> "p1", "p1", "p2"
$ seconds        <dbl> 30, 90, NA
   response_id participant_id        seconds 
             3              3              3 

A text label for the missing duration affects how the two measured durations are stored. c(30, 90, "unknown") coerces all three values to character before tibble() receives them. The resulting seconds column no longer supports numeric arithmetic.

1
2
3
4
5
6
with_label <- tibble(
  response_id = c("r1", "r2", "r3"),
  seconds = c(30, 90, "unknown")
)
with_label
typeof(with_label$seconds)
1
2
3
4
5
6
7
# A tibble: 3 × 2
  response_id seconds
  <chr>       <chr>  
1 r1          30     
2 r2          90     
3 r3          unknown
[1] "character"

In pl.DataFrame(), None marks the missing duration. with_missing["seconds"] extracts a Series, Polars’ object for a named column of values. Indexing that Series retrieves a single Python value. Positions 0 and 2 show what Python receives for a recorded duration and for a missing one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
with_missing = pl.DataFrame(
    {
        "response_id": ["r1", "r2", "r3"],
        "participant_id": ["p1", "p1", "p2"],
        "seconds": [30, 90, None],
    }
)
seconds = with_missing["seconds"]
seconds
type(seconds)
len(seconds)
seconds[0]
type(seconds[0])
seconds[2] is None
1
2
3
4
5
6
7
8
9
10
11
12
shape: (3,)
Series: 'seconds' [i64]
[
	30
	90
	null
]
<class 'polars.series.series.Series'>
3
30
<class 'int'>
True

The Series has length three and integer type, with null, Polars’ unavailable-value marker, at its third position. Its first item becomes the Python integer 30 when retrieved, while its third becomes None.

with_missing[["seconds"]] takes a list of column names and returns a one-column DataFrame. Its shape is (3, 1). The Series has shape (3,) and contains the same three entries, including the null.

1
2
3
4
seconds_table = with_missing[["seconds"]]
seconds_table
type(seconds_table)
seconds_table.shape
1
2
3
4
5
6
7
8
9
10
11
12
shape: (3, 1)
┌─────────┐
│ seconds │
│ ---     │
│ i64     │
╞═════════╡
│ 30      │
│ 90      │
│ null    │
└─────────┘
<class 'polars.dataframe.frame.DataFrame'>
(3, 1)

A schema pairs each column name with its type. In with_missing.schema, the identifiers are String and seconds is Int64, the types displayed as str and i64. get_columns() returns one Series per column. The lengths include the null at the third position in seconds. What happens if the duration list has only two entries for the three response IDs?

1
2
with_missing.schema
[len(column) for column in with_missing.get_columns()]
1
2
Schema({'response_id': String, 'participant_id': String, 'seconds': Int64})
[3, 3, 3]
1
2
# Deliberate error: columns of unequal length
pl.DataFrame({"response_id": ["r1", "r2", "r3"], "seconds": [30, 90]})
1
polars.exceptions.ShapeError: could not create a new DataFrame: height of column 'seconds' (2) does not match height of column 'response_id' (3)

Replacing None with "unknown" mixes integers and text. With its default setting of strict=True, pl.DataFrame() rejects this input. With strict=False, it builds the table. What type does the schema give the seconds column?

1
2
# Deliberate error: a string among integers with the default strict=True
pl.DataFrame({"response_id": ["r1", "r2", "r3"], "seconds": [30, 90, "unknown"]})
1
TypeError: unexpected value while building Series of type Int64; found value of type String: "unknown"
1
2
3
4
5
6
with_label = pl.DataFrame(
    {"response_id": ["r1", "r2", "r3"], "seconds": [30, 90, "unknown"]},
    strict=False,
)
with_label
with_label.schema
1
2
3
4
5
6
7
8
9
10
11
shape: (3, 2)
┌─────────────┬─────────┐
│ response_id ┆ seconds │
│ ---         ┆ ---     │
│ str         ┆ str     │
╞═════════════╪═════════╡
│ r1          ┆ 30      │
│ r2          ┆ 90      │
│ r3          ┆ unknown │
└─────────────┴─────────┘
Schema({'response_id': String, 'seconds': String})

With strict=False, the schema lists seconds as String. The displayed 30 and 90 are text, so dividing this column by 60 would fail. With None in the third position, the two measured durations are integers and can be converted to minutes.

5.3 Object names and column names in R

To flag responses longer than 60 seconds, we use the three recorded durations in responses. If the session also contains an object named seconds, which values will R compare? responses$seconds explicitly retrieves the column, and threshold <- 60 names the cutoff in the session.

1
2
3
threshold <- 60
responses$seconds
responses$seconds > threshold
1
2
[1]  30  90 120
[1] FALSE  TRUE  TRUE

In mutate(responses, over_threshold = seconds > threshold), dplyr looks for each name among the columns of responses first. It finds seconds there. Because the table has no threshold column, it uses threshold from the surrounding R environment, here the session. This lookup rule is called data masking. mutate() returns a table with the flags in a new column named over_threshold. The call displays that table without assigning it to responses.

1
mutate(responses, over_threshold = seconds > threshold)
1
2
3
4
5
6
# A tibble: 3 × 4
  response_id participant_id seconds over_threshold
  <chr>       <chr>            <dbl> <lgl>         
1 r1          p1                  30 FALSE         
2 r2          p1                  90 TRUE          
3 r3          p2                 120 TRUE          

In the session, seconds <- 45 assigns one number to seconds. Comparing it with threshold gives one flag. How many flags does the same comparison produce inside mutate()? $over_threshold extracts them for display.

1
2
3
seconds <- 45
seconds > threshold
mutate(responses, over_threshold = seconds > threshold)$over_threshold
1
2
[1] FALSE
[1] FALSE  TRUE  TRUE

Outside mutate(), the comparison uses 45 and returns one FALSE. Inside mutate(), it uses the three values in the seconds column. In response order, the two TRUE values correspond to r2 and r3, whose durations exceed 60 seconds.

The .data pronoun marks a name as a column reference inside a data-masking expression. .data$seconds requests the table’s column regardless of a session object with the same name.

1
mutate(responses, over_threshold = .data$seconds > threshold)$over_threshold
1
[1] FALSE  TRUE  TRUE

The .env pronoun requests an object from the surrounding environment. Here .env$threshold refers to the session’s threshold, even if the table later gains a column named threshold. In .data$seconds > .env$threshold, the code states the source of each name.

1
mutate(responses, over_threshold = .data$seconds > .env$threshold)$over_threshold
1
[1] FALSE  TRUE  TRUE

In select(responses, seconds), dplyr uses the name seconds to choose a column. The returned column contains the three response times, even with seconds set to 45 in the session. where(is.numeric) tests each column with is.numeric(). Only seconds is numeric here, so both calls return the same one-column table.

1
2
select(responses, seconds)
select(responses, where(is.numeric))
1
2
3
4
5
6
7
8
9
10
11
12
# A tibble: 3 × 1
  seconds
    <dbl>
1      30
2      90
3     120
# A tibble: 3 × 1
  seconds
    <dbl>
1      30
2      90
3     120

5.4 Series, expressions, and contexts in Polars

How can a duration in minutes be added to each response’s row? Here seconds = responses["seconds"] retrieves the Series from the original table, where r3 took 120 seconds. Dividing this Series by 60 returns all three durations in minutes. The displayed type f64 stands for 64-bit floating-point values.

1
2
seconds = responses["seconds"]
seconds / 60
1
2
3
4
5
6
7
shape: (3,)
Series: 'seconds' [f64]
[
	0.5
	1.5
	2.0
]

The converted Series contains the durations in row order but no response IDs. A Polars expression lets us describe the conversion in terms of the table’s columns and return the result alongside those identifiers. In pl.col("seconds") / 60, pl.col("seconds") names the column and / 60 specifies the conversion.

1
2
3
minutes_expr = pl.col("seconds") / 60
type(minutes_expr)
print(minutes_expr)
1
2
<class 'polars.expr.expr.Expr'>
[(col("seconds")) / (dyn int: 60)]

The expression names the column to divide by 60 but contains none of the three response times. Applying it to responses uses the three values in that table’s seconds column.

A context determines how Polars uses an expression to form a result table. In responses.select(minutes=minutes_expr), the select() context returns just the requested column, named minutes.

1
responses.select(minutes=minutes_expr)
1
2
3
4
5
6
7
8
9
10
shape: (3, 1)
┌─────────┐
│ minutes │
│ ---     │
│ f64     │
╞═════════╡
│ 0.5     │
│ 1.5     │
│ 2.0     │
└─────────┘

With with_columns(), the same expression adds minutes to the original columns. Each converted duration appears alongside its response identifier and original seconds.

1
responses.with_columns(minutes=minutes_expr)
1
2
3
4
5
6
7
8
9
10
shape: (3, 4)
┌─────────────┬────────────────┬─────────┬─────────┐
│ response_id ┆ participant_id ┆ seconds ┆ minutes │
│ ---         ┆ ---            ┆ ---     ┆ ---     │
│ str         ┆ str            ┆ i64     ┆ f64     │
╞═════════════╪════════════════╪═════════╪═════════╡
│ r1          ┆ p1             ┆ 30      ┆ 0.5     │
│ r2          ┆ p1             ┆ 90      ┆ 1.5     │
│ r3          ┆ p2             ┆ 120     ┆ 2.0     │
└─────────────┴────────────────┴─────────┴─────────┘

The first .shape gives the dimensions of the table returned by with_columns(). The second gives the dimensions of responses.

1
2
responses.with_columns(minutes=minutes_expr).shape
responses.shape
1
2
(3, 4)
(3, 3)

Only the returned table has four columns. Assigning it to a name makes the minutes available for another calculation.

The name "seconds" can identify a column or be a text value in its own right. In select(), a plain string is interpreted as a column reference. Thus copied="seconds" selects the numeric column, while pl.lit("seconds") supplies the word itself as label.

1
responses.select(copied="seconds", label=pl.lit("seconds"))
1
2
3
4
5
6
7
8
9
10
shape: (3, 2)
┌────────┬─────────┐
│ copied ┆ label   │
│ ---    ┆ ---     │
│ i64    ┆ str     │
╞════════╪═════════╡
│ 30     ┆ seconds │
│ 90     ┆ seconds │
│ 120    ┆ seconds │
└────────┴─────────┘

An expression can also be built through a sequence of methods. .truediv(60) performs the same division as / 60 and returns an expression. Its .alias("minutes") method assigns an output name before the expression is used in a context. Printing the expression shows the calculation and its name; passing it to responses.select() produces the three converted values.

1
2
print(pl.col("seconds").truediv(60).alias("minutes"))
responses.select(pl.col("seconds").truediv(60).alias("minutes"))
1
2
3
4
5
6
7
8
9
10
11
[(col("seconds")) / (dyn int: 60)].alias("minutes")
shape: (3, 1)
┌─────────┐
│ minutes │
│ ---     │
│ f64     │
╞═════════╡
│ 0.5     │
│ 1.5     │
│ 2.0     │
└─────────┘

5.5 Output lengths and the shape of a calculation

How long did each response take in minutes, and what is the total time for all three responses? The conversion gives one value per response. The total is one number, whether we report it on its own or place it beside each duration to calculate that response’s share.

mutate(responses, minutes = seconds / 60) divides each value in the seconds column by 60. The returned table pairs each response ID with its time in seconds and minutes.

1
mutate(responses, minutes = seconds / 60)
1
2
3
4
5
6
# A tibble: 3 × 4
  response_id participant_id seconds minutes
  <chr>       <chr>            <dbl>   <dbl>
1 r1          p1                  30     0.5
2 r2          p1                  90     1.5
3 r3          p2                 120     2  

sum(seconds) adds the three durations. For the three responses together, summarise() returns the sum in a single row under the name total_seconds.

1
summarise(responses, total_seconds = sum(seconds))
1
2
3
4
# A tibble: 1 × 1
  total_seconds
          <dbl>
1           240

The 240 seconds in this row are the total time for all three responses.

To calculate each response’s share of the total time, we need its own duration and the total together. Inside mutate(), the single value from sum(seconds) is repeated beside each of the three responses.

1
mutate(responses, total_seconds = sum(seconds))
1
2
3
4
5
6
# A tibble: 3 × 4
  response_id participant_id seconds total_seconds
  <chr>       <chr>            <dbl>         <dbl>
1 r1          p1                  30           240
2 r2          p1                  90           240
3 r3          p2                 120           240

For r1, seconds is 30 and total_seconds is 240. This response accounts for 30 / 240, or 12.5% of the total time. Adding the entries in total_seconds would count the same 240 seconds three times.

To report the total in minutes, we can first convert each duration and then sum the converted column. The intermediate table, converted, has one row per response; the summary has one row for all three responses.

The native pipe |> writes this sequence without assigning an intermediate name. It passes the value on its left as the first argument of the call on its right. Here mutate() receives responses, and summarise() receives the converted table.

1
2
3
4
5
converted <- mutate(responses, minutes = seconds / 60)
summarise(converted, total_minutes = sum(minutes))
responses |>
  mutate(minutes = seconds / 60) |>
  summarise(total_minutes = sum(minutes))
1
2
3
4
5
6
7
8
# A tibble: 1 × 1
  total_minutes
          <dbl>
1             4
# A tibble: 1 × 1
  total_minutes
          <dbl>
1             4

mutate() accepts a result of one value per row or a single value to repeat. One adjustment of 10 fits all three rows. With only two adjustments, the third row has no value of its own.

1
mutate(responses, adjustment = 10)
1
2
3
4
5
6
# A tibble: 3 × 4
  response_id participant_id seconds adjustment
  <chr>       <chr>            <dbl>      <dbl>
1 r1          p1                  30         10
2 r2          p1                  90         10
3 r3          p2                 120         10
1
2
# Deliberate error: an output of length 2 for a table of 3 rows
mutate(responses, adjustment = c(10, 20))
1
2
3
4
Error in `mutate()`:
ℹ In argument: `adjustment = c(10, 20)`.
Caused by error:
! `adjustment` must be size 3 or 1, not 2.

Why does seconds + c(10, 20) work inside mutate() when c(10, 20) alone failed? R adds 10, 20, and then 10 again to the three durations. The addition produces a warning because three is not a multiple of two. By the time mutate() checks the result, 40, 110, and 130 already fill three rows. The warning matters if r3 was never meant to receive 10.

responses.with_columns(minutes=pl.col("seconds") / 60) adds one conversion per response in Polars. The expression uses each row’s seconds, and the returned table has the identifiers and source measurements as well as the new minutes column.

1
responses.with_columns(minutes=pl.col("seconds") / 60)
1
2
3
4
5
6
7
8
9
10
shape: (3, 4)
┌─────────────┬────────────────┬─────────┬─────────┐
│ response_id ┆ participant_id ┆ seconds ┆ minutes │
│ ---         ┆ ---            ┆ ---     ┆ ---     │
│ str         ┆ str            ┆ i64     ┆ f64     │
╞═════════════╪════════════════╪═════════╪═════════╡
│ r1          ┆ p1             ┆ 30      ┆ 0.5     │
│ r2          ┆ p1             ┆ 90      ┆ 1.5     │
│ r3          ┆ p2             ┆ 120     ┆ 2.0     │
└─────────────┴────────────────┴─────────┴─────────┘

The expression method .sum() reduces the duration column to its total. A select() context containing only this expression returns that single value as a one-row table.

1
responses.select(total_seconds=pl.col("seconds").sum())
1
2
3
4
5
6
7
8
shape: (1, 1)
┌───────────────┐
│ total_seconds │
│ ---           │
│ i64           │
╞═══════════════╡
│ 240           │
└───────────────┘

The value 240 is the total time in seconds for all three responses. No single response ID identifies that total.

To express each duration as a share of the total, both values belong on each row. with_columns() repeats the sum beside all three durations.

1
responses.with_columns(total_seconds=pl.col("seconds").sum())
1
2
3
4
5
6
7
8
9
10
shape: (3, 4)
┌─────────────┬────────────────┬─────────┬───────────────┐
│ response_id ┆ participant_id ┆ seconds ┆ total_seconds │
│ ---         ┆ ---            ┆ ---     ┆ ---           │
│ str         ┆ str            ┆ i64     ┆ i64           │
╞═════════════╪════════════════╪═════════╪═══════════════╡
│ r1          ┆ p1             ┆ 30      ┆ 240           │
│ r2          ┆ p1             ┆ 90      ┆ 240           │
│ r3          ┆ p2             ┆ 120     ┆ 240           │
└─────────────┴────────────────┴─────────┴───────────────┘

Response r1 took 30 of the 240 seconds, or 12.5% of the total time. Adding the three entries in total_seconds would count that total three times.

To find the total in minutes, with_columns() first converts each response’s seconds to minutes. We can name that table converted or call .select() directly on the returned table in a method chain. Here .sum() adds the three minutes values, so .select() returns a one-row table. The outer parentheses let the chain span several lines.

1
2
3
4
5
6
converted = responses.with_columns(minutes=pl.col("seconds") / 60)
converted.select(total_minutes=pl.col("minutes").sum())
(
    responses.with_columns(minutes=pl.col("seconds") / 60)
    .select(total_minutes=pl.col("minutes").sum())
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
shape: (1, 1)
┌───────────────┐
│ total_minutes │
│ ---           │
│ f64           │
╞═══════════════╡
│ 4.0           │
└───────────────┘
shape: (1, 1)
┌───────────────┐
│ total_minutes │
│ ---           │
│ f64           │
╞═══════════════╡
│ 4.0           │
└───────────────┘

A table’s height is its number of rows. Here pl.lit(10) is a scalar expression. Polars repeats its single value for all three rows and displays its type as i32, a 32-bit integer. A Series with two adjustments has only two entries for those three rows.

1
responses.with_columns(adjustment=pl.lit(10))
1
2
3
4
5
6
7
8
9
10
shape: (3, 4)
┌─────────────┬────────────────┬─────────┬────────────┐
│ response_id ┆ participant_id ┆ seconds ┆ adjustment │
│ ---         ┆ ---            ┆ ---     ┆ ---        │
│ str         ┆ str            ┆ i64     ┆ i32        │
╞═════════════╪════════════════╪═════════╪════════════╡
│ r1          ┆ p1             ┆ 30      ┆ 10         │
│ r2          ┆ p1             ┆ 90      ┆ 10         │
│ r3          ┆ p2             ┆ 120     ┆ 10         │
└─────────────┴────────────────┴─────────┴────────────┘
1
2
# Deliberate error: a Series of length 2 for a table of 3 rows
responses.with_columns(adjustment=pl.Series([10, 20]))
1
polars.exceptions.ShapeError: can't broadcast Series 'adjustment' of length 2 to length 3

The error reports a Series of length 2 for a table of height 3. A Series passed directly as a new column must have three elements here. Even pl.Series([10]) fails, although the scalar pl.lit(10) fills all three rows.

This post is licensed under CC BY-NC 4.0 by the author.