markfairbanks / tidypolars

Tidy interface to polars
http://tidypolars.readthedocs.io
MIT License
337 stars 11 forks source link

`from_polars`? #225

Closed eutwt closed 1 week ago

eutwt commented 1 year ago

I feel like I'm missing something, I see from_pandas, but surely there's a way to start from a polars dataframe too right?

markfairbanks commented 1 year ago

Yep - it's there. It looks like I missed adding it to the documentation.

import tidypolars as tp
import polars as pl

polars_df = pl.DataFrame(dict(x = range(3), y = range(3)))

tidypolars_df = tp.from_polars(polars_df)

type(tidypolars_df)
tidypolars.tibble.Tibble
eutwt commented 1 year ago

Another thing I think would be useful to document (assuming I haven't missed it) is the fact that tp.col('x') seems to give a polars expression (?) so that tp.col('x') has all the polars methods available (?). Took me a while to figure that out. For example, I just spent a good amount of time trying to figure out how to do the action below with tidypolars methods before realizing I could just use the polars methods. In retrospect it seems obvious it would work this way, but I'm sure there are others out there as slow as me :)

df.summarise(y = tp.col('y').str.concat(', '), by = tp.col('x').alias('x_group'))
markfairbanks commented 1 year ago

Yep, that's a good idea. I'll add that too.