As I have a background in R the explorer package of Nx caught my interest.
In R I often need the value of a particular cell of a dataframe.
I have not found a function in Explorer.DataFrame yet that does the same.
I have seen
take (an entire row) and
pull (an entire column) though. So is it the best way to pull a series and then get the nth element of that series? Is this efficient?
On a site note: Are there downsides using Explorer.DataFrame as opposed to - let’s say - maps/structs?
Hi @Nefcairon! Glad to hear it caught your interest. Yes, at the minute the best way to pull a series and then get the nth element of that series is to use
pull and then index. But the
Access protocol is implemented for
Explorer.Series. So you can access a given cell like so:
df = Explorer.Datasets.fossil_fuels() # as an example
df["country"] # gives us "ALBANIA"
# or without using `Access`:
It’s very efficient either way. In both cases, it’s almost entirely ‘Rust-side’ (as the default backend for Explorer is
polars, which is a very, very fast Rust dataframe library).
What kind of downsides are you thinking of? Because the default backend is in Rust, it has to be compiled, which means having
rustc installed. There’s work being done to provide precompiled binaries. And since it’s not just a list of maps/structs, you don’t have access to your typical
Map functionality. It’s a different API. In return you get orders of magnitude faster operation and functionality that’s harder, slower, or more verbose with lists of maps/structs, like joins.
Thanks a lot for your response.
What I was looking for was the
Access protocol. That is clearly faster to type and similar to R.
Yea, I looked at the implementation details (down to Rust). I installed Rust via asdf and was very fast ready to go.
None, that’s why I asked
My first “use case” will be reading rows of database tables into dataframes, transform them via
Explorer.DataFrame API and feed them into Phoenix Liveview Surface components (sortable table and such). I know dataframes won’t be necessary therefore, but I love to work with them