Skip to content

Chapter 5 polars - #259

Closed
rinman57 wants to merge 17 commits into
data-8:mainfrom
dubois-ctds:chapter-5-polars
Closed

rinman57 wants to merge 17 commits into
data-8:mainfrom
dubois-ctds:chapter-5-polars

Conversation

@rinman57

Copy link
Copy Markdown

No description provided.

- .rename requires a dictionary, will we be teaching this?
- POLARS_CHANGE for the PercentFormatter
- nba_salaries.sort(pl.nth(0)).head(5) -->  .sort using column indexes, cannot just use a number to sort
nothing out of the ordinary
- with or without `.alias()`: change = (us_pop_by_age.get_column("2019") - us_pop_by_age.get_column("2014")).alias("Change")
- with pl.Config(tbl_rows=-1) --> to display every row
- matplotlib is used for visualization for now
- `Table().with_column('Chapters', huck_finn_chapters)` builds a one-column DataFrame from a named Series: `pl.DataFrame([pl.Series('Chapters', huck_finn_chapters)])`.
- The DataFrame display shows the first five and last five rows. A `datascience` table showed the first ten.
- `np.char.count(chapters, name)` counts a literal substring. `Series.str.count_matches(name)` treats the pattern as a regular expression, so the call passes `literal=True`.
- `np.cumsum(...)` is `Series.cum_sum()` on that count Series.
- `Table().with_columns([name, values, ...])` took a flat list of labels and arrays. The DataFrame is a list of named Series.
- `np.arange(1, 44, 1)` and `np.arange(1, 48, 1)` are `range(1, 44)` and `range(1, 48)`, passed as a Series named `Chapter`.
- `Table.with_column(name, values)` is `DataFrame.with_columns(pl.Series(name, values))`.
- `cum_counts.plot(column_for_xticks=3)` plotted every other column against column 3 (`Chapter`). Polars does not plot, so each name is one `plots.plot` of `Chapter` against that name. The Little Women call used column 5, which is also `Chapter`.

POLARS_CHANGE:

- Comment on `literal=True`: `count_matches` treats the pattern as a regular expression unless `literal=True`. The same comment is on the Huckleberry Finn counts and the Little Women counts.
- Comment on the plots: Polars does not plot, so each name is drawn against `Chapter`.
- `fmt_str_lengths=160` on the Little Women chapter DataFrame, same reason as in Plotting the Classics.
- `np.char.count(chapters, '.')` counts periods. `count_matches('.')` without `literal=True` counts every character, because `.` matches any character in a regular expression.
- `Table().with_columns([name, values, ...])` is again a DataFrame built from named Series.
- `table.column(index)` is `DataFrame.to_series(index)`. The scatter still uses position 1 for the period counts and position 0 for the chapter lengths.

POLARS_CHANGE:

- Comment on `literal=True` for `'.'`: `count_matches` treats `'.'` as a regular expression unless `literal=True`.
arrays --> pl.Series
- table methods are changed to adapt to polars
- pl.int_range --> for integers
- pl.linear_space --> for fractional / float steps
- added extra notes for students to understand `.product()`
"The expression below has three pieces:"
arrays --> pl.Series
@rinman57 rinman57 closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant