Skip to main content

Unofficial convenience functions that deal with fragmenting Pandas dataframes.

Project description

pandas-refract is an MIT licensed Python package with a simple function that allows users to divide their dataframes by the ‘Truthy’ and ‘Falseyness’ of a provided array.

Because this library deals with splitting dataframes by its values, it uses imagery of light - refract and disperse, like light entering a prism. Eventually, the goal of this package is additional features to the Pandas library that allows users to .pop rows from a dataframe where a condition is met, etc. As far as I can tell this is not possible like the below example.

Ideal case would be:

target_df = df.pop(df['target_column'] == 'target_value')
non_target_df = df

What is required now is:

target_df = df[df['target_column'] == 'target_value']
non_target_df = df[df['target_column'] != 'target_value']

With pandas-refract this becomes:

target_df, non_target_df = refract(df, df['target_column'] == 'target_value']]

Obviously, this package is not providing anything not currently possible in the current Pandas library. It does, however, add a layer of convenience for more complex slicing where you need to separate, not remove, rows by conditions.

Examples

Simplest example of current Pandas requires:

df1 = df[df.column.notnull()].reset_index(drop=True)
df2 = df[df.column.isnull()].reset_index(drop=True)

or:

df1 = df[df.column == 'test_string'].reset_index(drop=True)
df2 = df[df.column != 'test_string'].reset_index(drop=True)

With pandas-refract this becomes:

df1, df2 = refract(df, df.column.notnull(), True]

and:

df1, df2 = refract(df, df.column == test_string', True]

But you don’t have to pass it explicit boolean arrays:

data = {'a': ['', 'truthy', '', 'truthy'],
        'b': [0, 1, 2, 3]
        }

df = pd.DataFrame(data)

truthy_df, falsey_df = refract(df, df.a)

More complex examples: (where ‘a’ is Falsey and ‘b’ is an odd number)

df1, df2 = refract(df, ((~df.a) & (df.b % 2 == 1)))

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

pandas_refract-1.2.4.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pandas_refract-1.2.4-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pandas_refract-1.2.4.tar.gz.

File metadata

  • Download URL: pandas_refract-1.2.4.tar.gz
  • Upload date:
  • Size: 3.7 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.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pandas_refract-1.2.4.tar.gz
Algorithm Hash digest
SHA256 de68018bd403394770bd5001b547f77d114530cb3e518ffc869ce083d560a79d
MD5 9ef53bf232b0d19b1810527783b7c48f
BLAKE2b-256 7580d95038bd5026b5cf81a8961183a2ae9add78a2226c3b744b59ed68216950

See more details on using hashes here.

File details

Details for the file pandas_refract-1.2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: pandas_refract-1.2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pandas_refract-1.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2decf0988216f0f35c9578be9556cbf227672ad99358253e182aa2a574604c9b
MD5 cfdfc08c0d7abe64ddbc91018ccc0a70
BLAKE2b-256 29c41f78a1d3a758f1feb6dad1e7f3103579c81b47496c98767223bdf61ce5e5

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 Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page