랭킹으로 돌아가기

jmcarpenter2/swifter

Python

A package which efficiently applies any function to a pandas dataframe or series in the fastest available manner

pandaspandas-dataframeparallel-computingparallelizationdaskmodin
스타 성장
스타
2.6k
포크
104
주간 성장
이슈
24
1k2k
2018년 4월2021년 1월2023년 10월2026년 7월
아티팩트PyPIpip install swifter
README

swifter

A package which efficiently applies any function to a pandas dataframe or series in the fastest available manner.

PyPI version CircleCI codecov Code style: black GitHub stars PyPI - Downloads

Blog posts

Documentation

To know about latest improvements, please check the changelog.

Further documentations on swifter is available here.

Check out the examples notebook, along with the speed benchmark notebook. The benchmarks are created using the library perfplot.

Installation:

$ pip install -U pandas # upgrade pandas
$ pip install swifter # first time installation
$ pip install swifter[notebook] # first time installation including dependency for rich progress bar in jupyter notebooks
$ pip install swifter[groupby] # first time installation including dependency for groupby.apply functionality

$ pip install -U swifter # upgrade to latest version if already installed
$ pip install -U swifter[notebook] # upgrade to latest version to include dependency for rich progress bar in jupyter notebooks
$ pip install -U swifter[groupby] # upgrade to latest version to include dependency for groupby.apply functionality

alternatively, to install on Anaconda:

conda install -c conda-forge swifter  # Install swifter
conda install -c conda-forge swifter>=1.3.2 ray>=1.0.0  # Install swifter with dependency for groupby.apply

...after installing, import swifter into your code along with pandas using:

import pandas as pd
import swifter

...alternatively, swifter can be used with modin dataframes in the same manner:

import modin.pandas as pd
import swifter

NOTE: if you import swifter before modin, you will have to additionally register modin: swifter.register_modin()

Easy to use

df = pd.DataFrame({'x': [1, 2, 3, 4], 'y': [5, 6, 7, 8]})

# runs on single core
df['x2'] = df['x'].apply(lambda x: x**2)
# runs on multiple cores
df['x2'] = df['x'].swifter.apply(lambda x: x**2)

# use swifter apply on whole dataframe
df['agg'] = df.swifter.apply(lambda x: x.sum() - x.min())

# use swifter apply on specific columns
df['outCol'] = df[['inCol1', 'inCol2']].swifter.apply(my_func)
df['outCol'] = df[['inCol1', 'inCol2', 'inCol3']].swifter.apply(my_func,
             positional_arg, keyword_arg=keyword_argval)

Vectorizes your function, when possible

Alt text

When vectorization is not possible, automatically decides which is faster: to use dask parallel processing or a simple pandas apply

Alt text

Highly performant, even for groupby applies

Alt text

See the speed benchmark notebook for source of the above performance plots.

Notes

  1. The function is documented in the .py file. In Jupyter Notebooks, you can see the docs by pressing Shift+Tab(x3). Also, check out the complete documentation here along with the changelog.

  2. Please upgrade your version of pandas, as the pandas extension api used in this module is a recent addition to pandas.

  3. Import modin before importing swifter, if you wish to use modin with swifter. Otherwise, use swifter.register_modin() to access it.

  4. Do not use swifter to apply a function that modifies external variables. Under the hood, swifter does sample applies to optimize performance. These sample applies will modify the external variable in addition to the final apply. Thus, you will end up with an erroneously modified external variable.

  5. It is advised to disable the progress bar if calling swifter from a forked process as the progress bar may get confused between various multiprocessing modules.

  6. If swifter return is different than pandas try explicitly casting type e.g.: df.swifter.apply(lambda x: float(np.angle(x)))

관련 저장소
Asabeneh/30-Days-Of-Python

The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw

PythonPyPI30-days-of-pythonpython
68.8k12.8k
jakevdp/PythonDataScienceHandbook

Python Data Science Handbook: full text in Jupyter Notebooks

Jupyter NotebookMIT Licensescikit-learnnumpy
jakevdp.github.io/PythonDataScienceHandbook
49.3k19.1k
pandas-dev/pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more

PythonPyPIBSD 3-Clause "New" or "Revised" Licensedata-analysispandas
pandas.pydata.org
49.3k20.2k
microsoft/Data-Science-For-Beginners

10 Weeks, 20 Lessons, Data Science for All!

Jupyter NotebookMIT Licensedata-sciencepython
36.3k7.3k
tqdm/tqdm

:zap: A Fast, Extensible Progress Bar for Python and CLI

PythonPyPIOtherprogressbarprogressmeter
tqdm.github.io
31.2k1.5k
donnemartin/data-science-ipython-notebooks

Data science Python notebooks: Deep learning (TensorFlow, Theano, Caffe, Keras), scikit-learn, Kaggle, big data (Spark, Hadoop MapReduce, HDFS), matplotlib, pandas, NumPy, SciPy, Python essentials, AWS, and various command lines.

PythonPyPIOtherpythonmachine-learning
29.3k8k
ranaroussi/yfinance

Download market data from Yahoo! Finance's API

PythonPyPIApache License 2.0pythonpandas
ranaroussi.github.io/yfinance
24.8k3.4k
sinaptik-ai/pandas-ai

Chat with your database or your datalake (SQL, CSV, parquet). PandasAI makes data analysis conversational using LLMs and RAG.

PythonPyPIOtherllmpandas
pandas-ai.com
23.7k2.3k
huggingface/datasets

🤗 The largest hub of ready-to-use datasets for AI models with fast, easy-to-use and efficient data manipulation tools

PythonPyPIApache License 2.0nlpdatasets
huggingface.co/docs/datasets
21.7k3.3k
bbfamily/abu

阿布量化交易系统(股票,期权,期货,比特币,机器学习) 基于python的开源量化交易,量化投资架构

PythonPyPIGNU General Public License v3.0quanttrade
abuquant.com
17.9k4.6k
Kanaries/pygwalker

PyGWalker: Turn your dataframe into an interactive UI for visual analysis

PythonPyPIApache License 2.0data-analysispandas
kanaries.net/pygwalker
15.9k882
waditu/tushare

TuShare is a utility for crawling historical data of China stocks

PythonPyPIBSD 3-Clause "New" or "Revised" Licensepythonfinance
15.3k4.4k