Repository navigation
Chapter 5 polars - #259
Closed
rinman57 wants to merge 17 commits into
Closed
Chapter 5 polars#259rinman57 wants to merge 17 commits into
rinman57 wants to merge 17 commits into
Conversation
- .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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.