Skip to main content

df4loop supports general purpose processe that requires a combination of both pandas.DataFrame and loop.

Project description

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()

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

df4loop-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

df4loop-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: df4loop-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for df4loop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 108eb3d469d7c5222c96ee5e56d8a1c0166e7c3a16bb2aa394932487d3402d19
MD5 cbec06440acb00bbb0cb882290282cdc
BLAKE2b-256 2feae9402f2b8cbdc7c810fed8fe61f7d551fe87d75562c6992cbf0cee04e7fb

See more details on using hashes here.

File details

Details for the file df4loop-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: df4loop-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for df4loop-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7840f6f89acd555869f63daf1db19446b9689e6ecebdf0f5f0e43c936c4d0e3
MD5 b44d559ad9ef69111dd51ed48f3eb51d
BLAKE2b-256 66b61668008b91b396c23fe526ab5d6a0534c776b8df77f0e13949babb6e38a8

See more details on using hashes here.

Supported by

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