kandi background

polars | Fast multithreaded DataFrame library in Rust and Python | GPU library

 by   pola-rs Rust Version: rust-polars-v0.20.0 License: MIT

 by   pola-rs Rust Version: rust-polars-v0.20.0 License: MIT

Download this library from

kandi X-RAY | polars Summary

polars is a Rust library typically used in Hardware, GPU, Numpy, Pandas applications. polars has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
Python Documentation | Rust Documentation | User Guide | Discord | StackOverflow.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • polars has a medium active ecosystem.
  • It has 5341 star(s) with 304 fork(s). There are 71 watchers for this library.
  • There were 1 major release(s) in the last 6 months.
  • There are 127 open issues and 1115 have been closed. On average issues are closed in 2 days. There are 9 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of polars is rust-polars-v0.20.0
polars Support
Best in #GPU
Average in #GPU
polars Support
Best in #GPU
Average in #GPU

quality kandi Quality

  • polars has no bugs reported.
polars Quality
Best in #GPU
Average in #GPU
polars Quality
Best in #GPU
Average in #GPU

securitySecurity

  • polars has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
polars Security
Best in #GPU
Average in #GPU
polars Security
Best in #GPU
Average in #GPU

license License

  • polars is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
polars License
Best in #GPU
Average in #GPU
polars License
Best in #GPU
Average in #GPU

buildReuse

  • polars releases are available to install and integrate.
  • Installation instructions, examples and code snippets are available.
polars Reuse
Best in #GPU
Average in #GPU
polars Reuse
Best in #GPU
Average in #GPU
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

polars Key Features

Fast multi-threaded DataFrame library in Rust | Python | Node.js

polars Examples and Code Snippets

  • Blazingly fast DataFrames in Rust, Python & Node.js
  • Python setup
  • Rust setup
  • [Python]: compile polars from source
  • Apply function to all columns of a Polars-DataFrame
  • How to define types of columns while loading dataframe in polars?
  • How to change axes labels to multiples of pi
  • Clip off pcolormesh outside of circular set_boundary in Cartopy
  • Geopandas - map and locaton plotting
  • Geopandas world map in Polar Stereographic projection with coloured oceans
  • Polar Stereographic projection of geopandas world map
  • Looping a script to produce multiple images
  • Converting Array{Array{Float64,1},1} to Array{Float64,2} in Julia
  • Strange behavior with contours in Cartopy polar stereographic plot

Blazingly fast DataFrames in Rust, Python & Node.js

>>> import polars as pl
>>> df = pl.DataFrame(
...     {
...         "A": [1, 2, 3, 4, 5],
...         "fruits": ["banana", "banana", "apple", "apple", "banana"],
...         "B": [5, 4, 3, 2, 1],
...         "cars": ["beetle", "audi", "beetle", "beetle", "beetle"],
...     }
... )

# embarrassingly parallel execution
# very expressive query language
>>> (
...     df
...     .sort("fruits")
...     .select(
...         [
...             "fruits",
...             "cars",
...             pl.lit("fruits").alias("literal_string_fruits"),
...             pl.col("B").filter(pl.col("cars") == "beetle").sum(),
...             pl.col("A").filter(pl.col("B") > 2).sum().over("cars").alias("sum_A_by_cars"),     # groups by "cars"
...             pl.col("A").sum().over("fruits").alias("sum_A_by_fruits"),                         # groups by "fruits"
...             pl.col("A").reverse().over("fruits").flatten().alias("rev_A_by_fruits"),           # groups by "fruits
...             pl.col("A").sort_by("B").over("fruits").flatten().alias("sort_A_by_B_by_fruits"),  # groups by "fruits"
...         ]
...     )
... )
shape: (5, 8)
┌──────────┬──────────┬──────────────┬─────┬─────────────┬─────────────┬─────────────┬─────────────┐
│ fruits   ┆ cars     ┆ literal_stri ┆ B   ┆ sum_A_by_ca ┆ sum_A_by_fr ┆ rev_A_by_fr ┆ sort_A_by_B │
│ ---      ┆ ---      ┆ ng_fruits    ┆ --- ┆ rs          ┆ uits        ┆ uits        ┆ _by_fruits  │
│ str      ┆ str      ┆ ---          ┆ i64 ┆ ---         ┆ ---         ┆ ---         ┆ ---         │
│          ┆          ┆ str          ┆     ┆ i64         ┆ i64         ┆ i64         ┆ i64         │
╞══════════╪══════════╪══════════════╪═════╪═════════════╪═════════════╪═════════════╪═════════════╡
│ "apple"  ┆ "beetle" ┆ "fruits"     ┆ 11  ┆ 4           ┆ 7           ┆ 4           ┆ 4           │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ "apple"  ┆ "beetle" ┆ "fruits"     ┆ 11  ┆ 4           ┆ 7           ┆ 3           ┆ 3           │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ "banana" ┆ "beetle" ┆ "fruits"     ┆ 11  ┆ 4           ┆ 8           ┆ 5           ┆ 5           │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ "banana" ┆ "audi"   ┆ "fruits"     ┆ 11  ┆ 2           ┆ 8           ┆ 2           ┆ 2           │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ "banana" ┆ "beetle" ┆ "fruits"     ┆ 11  ┆ 4           ┆ 8           ┆ 1           ┆ 1           │
└──────────┴──────────┴──────────────┴─────┴─────────────┴─────────────┴─────────────┴─────────────┘

Community Discussions

Trending Discussions on polars
  • Apply function to all columns of a Polars-DataFrame
  • Arrow IPC vs Feather
  • How to define types of columns while loading dataframe in polars?
  • How to change axes labels to multiples of pi
  • Drawing lines of constant latitude with cartopy on North Polar Stereo projection
  • Clip off pcolormesh outside of circular set_boundary in Cartopy
  • Geopandas - map and locaton plotting
  • Geopandas world map in Polar Stereographic projection with coloured oceans
  • Polar Stereographic projection of geopandas world map
  • Looping a script to produce multiple images
Trending Discussions on polars

QUESTION

Apply function to all columns of a Polars-DataFrame

Asked 2021-Jun-11 at 09:30

I know how to apply a function to all columns present in a Pandas-DataFrame. However, I have not figured out yet how to achieve this when using a Polars-DataFrame.

I checked the section from the Polars User Guide devoted to this topic, but I have not find the answer. Here I attach a code snippet with my unsuccessful attempts.

import numpy as np
import polars as pl
import seaborn as sns

# Loading toy dataset as Pandas DataFrame using Seaborn
df_pd = sns.load_dataset('iris')

# Converting Pandas DataFrame to Polars DataFrame
df_pl = pl.DataFrame(df_pd)

# Dropping the non-numeric column...
df_pd = df_pd.drop(columns='species')                     # ... using Pandas
df_pl = df_pl.drop('species')                             # ... using Polars

# Applying function to the whole DataFrame...
df_pd_new = df_pd.apply(np.log2)                          # ... using Pandas
# df_pl_new = df_pl.apply(np.log2)                        # ... using Polars?

# Applying lambda function to the whole DataFrame...
df_pd_new = df_pd.apply(lambda c: np.log2(c))             # ... using Pandas
# df_pl_new = df_pl.apply(lambda c: np.log2(c))           # ... using Polars?

Thanks in advance for your help and your time.

ANSWER

Answered 2021-Jun-11 at 09:30

You can use the expression syntax to select all columns with pl.col("*") and then map the numpy np.log2(..) function over the columns.

# option 1
df_pl = df_pl[pl.col("*").map(np.log2)]

# option 2
df_pl = df_pl.select(pl.col("*").map(np.log2))

Note that the difference between an apply and a map is that an apply would be called upon every numeric values, and the map over the whole Series. We choose map here, because that would be faster.

Edit: assign result to df_pl

Source https://stackoverflow.com/questions/67834912

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install polars

Install the latest polars version with:.
You can take latest release from crates.io, or if you want to use the latest features / performance improvements point to the master branch of this repo. Required Rust version >=1.58.

Support

Want to know about all the features Polars supports? Read the docs!.

DOWNLOAD this Library from

Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit