a-pandas-ex-apply-ignore-exceptions


Namea-pandas-ex-apply-ignore-exceptions JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/a_pandas_ex_apply_ignore_exceptions
SummaryUse DataFrame.apply / Series.apply with a default value for Exceptions
upload_time2023-01-06 15:49:59
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords dataframe series apply exception
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Use DataFrame.apply / Series.apply with a default value for Exceptions 



```python

pip install a-pandas-ex-apply-ignore-exceptions

```



```python



from a_pandas_ex_apply_ignore_exceptions import pd_add_apply_ignore_exceptions

import pandas as pd

pd_add_apply_ignore_exceptions()

df = pd.read_csv(

    "https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv"

)



# the Exception value is the first arg, the rest is just like apply

df1 = df.PassengerId.ds_apply_ignore(pd.NA, lambda x: x / 3)

df2 = df.ds_apply_ignore(pd.NA, lambda x: x["PassengerId"] / 3, axis=1)

df3 = df.PassengerId.ds_apply_ignore(pd.NA, lambda x: x / 0)

df4 = df.ds_apply_ignore(pd.NA, lambda x: x["PassengerId"] / 0, axis=1)

print(df1)

print(df2)

print(df3)

print(df4)





r"""

0        0.333333

1        0.666667

2        1.000000

3        1.333333

4        1.666667

          ...    

886    295.666667

887    296.000000

888    296.333333

889    296.666667

890    297.000000

Name: PassengerId, Length: 891, dtype: float64

0        0.333333

1        0.666667

2        1.000000

3        1.333333

4        1.666667

          ...    

886    295.666667

887    296.000000

888    296.333333

889    296.666667

890    297.000000

Length: 891, dtype: float64

0      <NA>

1      <NA>

2      <NA>

3      <NA>

4      <NA>

       ... 

886    <NA>

887    <NA>

888    <NA>

889    <NA>

890    <NA>

Name: PassengerId, Length: 891, dtype: object

0      <NA>

1      <NA>

2      <NA>

3      <NA>

4      <NA>

       ... 

886    <NA>

887    <NA>

888    <NA>

889    <NA>

890    <NA>

Length: 891, dtype: object



"""



		

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/a_pandas_ex_apply_ignore_exceptions",
    "name": "a-pandas-ex-apply-ignore-exceptions",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "DataFrame,Series,apply,Exception",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bd/bc/94c54b63fed32719648fa655df6d3893f4f2f7758397eb6c29107080715f/a_pandas_ex_apply_ignore_exceptions-0.10.tar.gz",
    "platform": null,
    "description": "\n# Use DataFrame.apply / Series.apply with a default value for Exceptions \n\n\n\n```python\n\npip install a-pandas-ex-apply-ignore-exceptions\n\n```\n\n\n\n```python\n\n\n\nfrom a_pandas_ex_apply_ignore_exceptions import pd_add_apply_ignore_exceptions\n\nimport pandas as pd\n\npd_add_apply_ignore_exceptions()\n\ndf = pd.read_csv(\n\n    \"https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv\"\n\n)\n\n\n\n# the Exception value is the first arg, the rest is just like apply\n\ndf1 = df.PassengerId.ds_apply_ignore(pd.NA, lambda x: x / 3)\n\ndf2 = df.ds_apply_ignore(pd.NA, lambda x: x[\"PassengerId\"] / 3, axis=1)\n\ndf3 = df.PassengerId.ds_apply_ignore(pd.NA, lambda x: x / 0)\n\ndf4 = df.ds_apply_ignore(pd.NA, lambda x: x[\"PassengerId\"] / 0, axis=1)\n\nprint(df1)\n\nprint(df2)\n\nprint(df3)\n\nprint(df4)\n\n\n\n\n\nr\"\"\"\n\n0        0.333333\n\n1        0.666667\n\n2        1.000000\n\n3        1.333333\n\n4        1.666667\n\n          ...    \n\n886    295.666667\n\n887    296.000000\n\n888    296.333333\n\n889    296.666667\n\n890    297.000000\n\nName: PassengerId, Length: 891, dtype: float64\n\n0        0.333333\n\n1        0.666667\n\n2        1.000000\n\n3        1.333333\n\n4        1.666667\n\n          ...    \n\n886    295.666667\n\n887    296.000000\n\n888    296.333333\n\n889    296.666667\n\n890    297.000000\n\nLength: 891, dtype: float64\n\n0      <NA>\n\n1      <NA>\n\n2      <NA>\n\n3      <NA>\n\n4      <NA>\n\n       ... \n\n886    <NA>\n\n887    <NA>\n\n888    <NA>\n\n889    <NA>\n\n890    <NA>\n\nName: PassengerId, Length: 891, dtype: object\n\n0      <NA>\n\n1      <NA>\n\n2      <NA>\n\n3      <NA>\n\n4      <NA>\n\n       ... \n\n886    <NA>\n\n887    <NA>\n\n888    <NA>\n\n889    <NA>\n\n890    <NA>\n\nLength: 891, dtype: object\n\n\n\n\"\"\"\n\n\n\n\t\t\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Use DataFrame.apply / Series.apply with a default value for Exceptions",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/a_pandas_ex_apply_ignore_exceptions"
    },
    "split_keywords": [
        "dataframe",
        "series",
        "apply",
        "exception"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01b8b797759e264dcc017a0b7bbcf0f67431dbb2d6ab8a137188fa73009b0347",
                "md5": "696832fe92b77238be2796485a9acf7e",
                "sha256": "85fcb1a09efdb3003500d938c34d75a17c4f3bc387e7a7aad5f23bc9cf135017"
            },
            "downloads": -1,
            "filename": "a_pandas_ex_apply_ignore_exceptions-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "696832fe92b77238be2796485a9acf7e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5568,
            "upload_time": "2023-01-06T15:49:58",
            "upload_time_iso_8601": "2023-01-06T15:49:58.154298Z",
            "url": "https://files.pythonhosted.org/packages/01/b8/b797759e264dcc017a0b7bbcf0f67431dbb2d6ab8a137188fa73009b0347/a_pandas_ex_apply_ignore_exceptions-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdbc94c54b63fed32719648fa655df6d3893f4f2f7758397eb6c29107080715f",
                "md5": "e4ae9b0db11ad16367d6138f2e83214f",
                "sha256": "479eec41c641162a36c0eaf2eb407207c19e3fa1bf9838bc5563ebf0c72f4b37"
            },
            "downloads": -1,
            "filename": "a_pandas_ex_apply_ignore_exceptions-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "e4ae9b0db11ad16367d6138f2e83214f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3712,
            "upload_time": "2023-01-06T15:49:59",
            "upload_time_iso_8601": "2023-01-06T15:49:59.639672Z",
            "url": "https://files.pythonhosted.org/packages/bd/bc/94c54b63fed32719648fa655df6d3893f4f2f7758397eb6c29107080715f/a_pandas_ex_apply_ignore_exceptions-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-06 15:49:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "a_pandas_ex_apply_ignore_exceptions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "a-pandas-ex-apply-ignore-exceptions"
}
        
Elapsed time: 0.43747s