Skip to main content

An easy to use library to speed up computation (by parallelizing on multi CPUs) with pandas.

Project description

# pandaral·lel
An easy to use library to speed up computation (by parallelizing on multi CPUs) with [pandas](https://pandas.pydata.org/).

## Requirements
- [pandas](https://pypi.org/project/pandas/)
- [pyarrow](https://pypi.org/project/pyarrow/)


## Warnings
- The V1.0 of this library is not yet released. API is able to change at any time.
- Parallelization has a cost (instanciating new processes, transmitting data via shared memory, etc ...), so parallelization is efficiant only if the amount of computation to parallelize is high enough. For very little amount of data, using parallezation not always worth it.
- Functions applied should NOT be lambda functions.

```python
import pandarallel
from math import sin

# FORBIDDEN
df.parallel_apply(lambda x: sin(x**2), axis=1)

# ALLOWED
def func(x):
return sin(x**2)

df.parallel_apply(func, axis=1)

```

## Examples
An example of each API is available in [examples.ipynb](https://github.com/nalepae/pandarallel/blob/master/examples.ipynb).

## Benchmark
For the `Dataframe.apply` example in [examples.ipynb](https://github.com/nalepae/pandarallel/blob/master/examples.ipynb), here is the comparative benchmark with "standard" `apply` and with `progress_apply` (error bars are too small to be displayed).
Computer used for this benchmark:
- OS: Linux Ubuntu 16.04
- Hardware: Intel Core i7 @ 3.40 GHz (8 cores, **but 4 "truely parallelizable" CPUs**)
- Number of workers (parallel processes) used: 4

![Benchmark](https://github.com/nalepae/pandarallel/blob/master/docs/apply_vs_parallel_apply.png)

For this given example, `parallel_apply` runs approximatively 3.7 faster than the "standard" `apply`.


## API
First, you have to import `pandarallel` (don't forget the double _l_):
```python
import pandarallel
```
### DataFrame.parallel_apply

If `df` is a pandas DataFrame, and `func` a function to apply to this DataFrame, replace
```python
df.apply(func, axis=1)
```
by
```python
df.parallel_apply(func, axis=1)
```

_Note: ``apply`` with ``axis=0`` is not yet implemented._

### Series.parallel_map
If `series` is a pandas Series (aka a DataFrame column), and `func` a function to apply to this Series, replace
```python
series.map(func)
```
by
```python
series.parallel_map(func)
```

### DataFrame.groupby.parallel_apply
If `df` is a pandas DataFrame, `col_name` is the name of a column of this DataFrame and `func` a function to apply to this column, replace
```python
df.groupby(col_name).apply(func)
```
by
```python
df.groupby(col_name).parallel_apply(func)
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandarallel-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file pandarallel-0.1.0.tar.gz.

File metadata

  • Download URL: pandarallel-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for pandarallel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1206292271366c6936bd50475933068bad262559e21477005b808f5f93d2479
MD5 746f5c85ba791348b6f4c80806aa2d57
BLAKE2b-256 c9671245bb2b72b7b427c39c70d4b56f332f9abbaaffb57cad29f558158108b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page