Skip to main content

df4loop

df4loop supports general purpose processes that requires a combination of both pandas.DataFrame and loop. Specifically, the mission of df4loop is to "speed up processing" and "make complex code intuitive" at low installation costs.

Installation

pip install df4loop

Usage

The following DataFrame is defined to assist users envision the use of df4loop.

import pandas as pd

sample_dict = {
    "column_1": [100, 200, 300, 400, 500],
    "column_2": ["A", "B", "C", "D", "E"],
    "column_3": ["a", "b", "c", "d", "e"],
}
df = pd.DataFrame.from_dict(sample_dict)
df
column_1 column_2 column_3
0 100 A a
1 200 B b
2 300 C c
3 400 D d
4 500 E e

DFIterator

DFIterator helps developers writing the following code. This is code written using pandas.DataFrame.iterrows for the purpose of referencing a value by row.

for index, row in df.iterrows():
    tmp = row["column_1"]

DFIterator reproduces this process and speeds it up. Actually, DataFrame and its row pandas.Series are converted to lists and dictionaries to speed up. However, the usage is almost the same.

from df4loop import DFIterator

df_iterator = DFIterator(df)
for index, row in df_iterator.iterrows():
    tmp = row["column_1"]

If you do not need to output the index, set return_indexes=False.

from df4loop import DFIterator

df_iterator = DFIterator(df)
for row in df_iterator.iterrows(return_indexes=False):
    tmp = row["column_1"]

DFGenerator

DFGenerator supports the generation of DataFrame with rows set by loops. Adding rows to the DataFrame in a loop will take a long time to process. The secret to speeding up is to organize rows in a list or dictionary and then make them pandas.DataFrame at once. DFGenerator supports this process for intuitive implementation.

The following code is an example of selecting the dict type as the row.

from df4loop import DFGenerator

# It is not necessary to specify columns.
df_generator = DFGenerator(columns=df.columns.values.tolist())
for _, row in df.iterrows():
    tmp_row = {
        "column_1": row["column_1"],
        "column_2": row["column_2"],
        "column_3": row["column_3"],
    }
    df_generator.append(tmp_row)
new_df = df_generator.generate_df()

The following code is an example of selecting the list type as the row. columns must be specified during initialization.

from df4loop import DFGenerator

df_generator = DFGenerator(columns=df.columns.values.tolist())
for _, row in df.iterrows():
    tmp_row = [
        row["column_1"],
        row["column_2"],
        row["column_3"],
    ]
    df_generator.append(tmp_row)
new_df = df_generator.generate_df()

Metadata

Release files for df4loop 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for df4loop 0.1.0
File Size Uploaded
df4loop-0.1.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for df4loop 0.1.0
File Interpreter ABI Platform
df4loop-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / df4loop-0.1.0.tar.gz

Download URL df4loop-0.1.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
108eb3d469d7c5222c96ee5e56d8a1c0166e7c3a16bb2aa394932487d3402d19
BLAKE2b-256 checksum
How to use checksums
2feae9402f2b8cbdc7c810fed8fe61f7d551fe87d75562c6992cbf0cee04e7fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

Release files / df4loop-0.1.0-py3-none-any.whl

Download URL df4loop-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7840f6f89acd555869f63daf1db19446b9689e6ecebdf0f5f0e43c936c4d0e3
BLAKE2b-256 checksum
How to use checksums
66b61668008b91b396c23fe526ab5d6a0534c776b8df77f0e13949babb6e38a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page