Basic usage
tidypolars methods are designed to work like tidyverse functions. This creates a dataframe:
- Creates a tibble (the data frame of tidypolars)
Here is the dataframe created:
shape: (6, 4)
┌───────────────────────┐
│ x y w z │
│ i64 i64 i64 str │
╞═══════════════════════╡
│ 0 6 6 a │
│ 1 7 7 a │
│ 2 8 8 b │
│ 3 9 9 c │
│ 4 10 10 d │
│ 5 11 11 e │
└───────────────────────┘
Data manipulation mirrors tidyverse function names:
- Select columns
x
,y
, andz
. - Select (filter) rows with
x < 4
andy > 7
. - Sort (arrange) the data by
z
(decreasing values) and then byx
(increasing values). - Create a variable
double_x
. - Create a variable
x_plus_y
. - Create a variable
z_num
that is1
whenz = 'a'
,2
whenz = 'b'
, and0
otherwise.
shape: (3, 6)
┌───────────────────────────────────────────────┐
│ x y z double_x x_plus_y z_num │
│ i64 i64 str i64 i64 i32 │
╞═══════════════════════════════════════════════╡
│ 3 9 c 6 12 0 │
│ 2 8 b 4 10 2 │
│ 1 7 a 2 8 1 │
└───────────────────────────────────────────────┘
Converting to/from pandas data frames
If one needs to use a package that requires pandas or polars dataframes,
you can convert from a tidypolars
tibble
to either of those
DataFrame
formats.
To convert from a pandas or polars DataFrame
to a
tidypolars's tibble
: