apply-pandas
Generic Apply Function for Pandas DataFrames
This repo demonstrates a powerful, simple and generic way to make an apply function for Pandas DataFrames. apply takes in a list of conditions (as strings) to apply to a dataframe, and returns the result of those applications.
This can be useful when you want to avoid writing huge chunks of code to filter data, or when you want to construct code based on other factors to give you a properly formatted result. Case in point - user input can be turned into well-defined string queries/filters on your DataFrame, with which you can return the appropriate data, without knowing those queries in advance.
Overview and Usage
The Apply function is wrapped in a functor so that we can cleanly separate verification and application. Furthermore, this also allows us to clearly bind the target DatFrame and the desired conditions together; something that might not always be easy when dealing with rapidly changing variables, while giving the programmer the option to call it when desired.
In effect, you can bind at creation, but can safely get the computation much, much later. Here's a code snippet that illustrates the usage of this method.
# First, we create our dummy data
df = pd.DataFrame(list(range(0, 100)), columns=["Slice"])
# Then a list of conditions to apply.
list_condns = ["frame['Slice']<5", "frame['Slice']%3==1"]
# To use the Apply() class,
# First create an object that binds DataFrame and conditions,
Applicator = Apply(df, list_condns)
# Call for the result when needed.
result = Applicator() #<--- returns pandas DataFrame
Notice that in list_condns, all of our conditions are made out to frame, regardless of the actual name of the actual target frame. This means that when you generate these conditions in real-time, you do not ever have to worry about getting the name of the variable - just make out the filter for frame, and we'll take care of the rest :)
Bugfixes and Improvements
This code is always ready for improvements, and to get rid of bugs - so please let me know if you've found anything, or how you've used this project! Hope you have fun with it :)
Metadata
Release files for apply-pandas 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| apply-pandas-0.0.1.tar.gz | 16.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apply_pandas-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.6 kB
Release files / apply-pandas-0.0.1.tar.gz
| Download URL | apply-pandas-0.0.1.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1af3f08ac7f79cabe6e6c1ba685f94689dcf7d571c4543f3634dedf47a727e57
|
|
BLAKE2b-256 checksum How to use checksums |
a69d8189c328e336660975190ee264d8f36dd07d44a2c305aedb0cc4001f7d84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / apply_pandas-0.0.1-py3-none-any.whl
| Download URL | apply_pandas-0.0.1-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
663fb92387d23e2f4aa1c75b28c7ef21438ca83fdc95a6b037a08dca21d13335
|
|
BLAKE2b-256 checksum How to use checksums |
128c17ed5ff9cab9945ae8d94cd09fe4b59eabd3d5ed752e6031d0fb0fba0646
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for apply-pandas 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.