pandas-schema


Namepandas-schema JSON
Version 0.3.6 PyPI version JSON
download
home_pagehttps://github.com/TMiguelT/PandasSchema
SummaryA validation library for Pandas data frames using user-friendly schemas
upload_time2022-02-18 23:51:28
maintainer
docs_urlNone
authorMichael Milton
requires_python
licenseMIT
keywords pandas csv verification schema
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            PandasSchema
************

For the full documentation, refer to the `Github Pages Website
<https://multimeric.github.io/PandasSchema/>`_.

======================================================================

PandasSchema is a module for validating tabulated data, such as CSVs
(Comma Separated Value files), and TSVs (Tab Separated Value files).
It uses the incredibly powerful data analysis tool Pandas to do so
quickly and efficiently.

For example, say your code expects a CSV that looks a bit like this:

.. code::

   Given Name,Family Name,Age,Sex,Customer ID
   Gerald,Hampton,82,Male,2582GABK
   Yuuwa,Miyake,27,Male,7951WVLW
   Edyta,Majewska,50,Female,7758NSID

Now you want to be able to ensure that the data in your CSV is in the
correct format:

.. code:: python

   import pandas as pd
   from io import StringIO
   from pandas_schema import Column, Schema
   from pandas_schema.validation import LeadingWhitespaceValidation, TrailingWhitespaceValidation, CanConvertValidation, MatchesPatternValidation, InRangeValidation, InListValidation

   schema = Schema([
       Column('Given Name', [LeadingWhitespaceValidation(), TrailingWhitespaceValidation()]),
       Column('Family Name', [LeadingWhitespaceValidation(), TrailingWhitespaceValidation()]),
       Column('Age', [InRangeValidation(0, 120)]),
       Column('Sex', [InListValidation(['Male', 'Female', 'Other'])]),
       Column('Customer ID', [MatchesPatternValidation(r'\d{4}[A-Z]{4}')])
   ])

   test_data = pd.read_csv(StringIO('''Given Name,Family Name,Age,Sex,Customer ID
   Gerald ,Hampton,82,Male,2582GABK
   Yuuwa,Miyake,270,male,7951WVLW
   Edyta,Majewska ,50,Female,775ANSID
   '''))

   errors = schema.validate(test_data)

   for error in errors:
       print(error)

PandasSchema would then output

.. code:: text

   {row: 0, column: "Given Name"}: "Gerald " contains trailing whitespace
   {row: 1, column: "Age"}: "270" was not in the range [0, 120)
   {row: 1, column: "Sex"}: "male" is not in the list of legal options (Male, Female, Other)
   {row: 2, column: "Family Name"}: "Majewska " contains trailing whitespace
   {row: 2, column: "Customer ID"}: "775ANSID" does not match the pattern "\d{4}[A-Z]{4}"



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TMiguelT/PandasSchema",
    "name": "pandas-schema",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pandas csv verification schema",
    "author": "Michael Milton",
    "author_email": "michael.r.milton@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/17/2a/d302fd983cdf3fb9a3d24d981e4a3c7340994030c0c46b397b4d9db83bea/pandas_schema-0.3.6.tar.gz",
    "platform": "",
    "description": "PandasSchema\n************\n\nFor the full documentation, refer to the `Github Pages Website\n<https://multimeric.github.io/PandasSchema/>`_.\n\n======================================================================\n\nPandasSchema is a module for validating tabulated data, such as CSVs\n(Comma Separated Value files), and TSVs (Tab Separated Value files).\nIt uses the incredibly powerful data analysis tool Pandas to do so\nquickly and efficiently.\n\nFor example, say your code expects a CSV that looks a bit like this:\n\n.. code::\n\n   Given Name,Family Name,Age,Sex,Customer ID\n   Gerald,Hampton,82,Male,2582GABK\n   Yuuwa,Miyake,27,Male,7951WVLW\n   Edyta,Majewska,50,Female,7758NSID\n\nNow you want to be able to ensure that the data in your CSV is in the\ncorrect format:\n\n.. code:: python\n\n   import pandas as pd\n   from io import StringIO\n   from pandas_schema import Column, Schema\n   from pandas_schema.validation import LeadingWhitespaceValidation, TrailingWhitespaceValidation, CanConvertValidation, MatchesPatternValidation, InRangeValidation, InListValidation\n\n   schema = Schema([\n       Column('Given Name', [LeadingWhitespaceValidation(), TrailingWhitespaceValidation()]),\n       Column('Family Name', [LeadingWhitespaceValidation(), TrailingWhitespaceValidation()]),\n       Column('Age', [InRangeValidation(0, 120)]),\n       Column('Sex', [InListValidation(['Male', 'Female', 'Other'])]),\n       Column('Customer ID', [MatchesPatternValidation(r'\\d{4}[A-Z]{4}')])\n   ])\n\n   test_data = pd.read_csv(StringIO('''Given Name,Family Name,Age,Sex,Customer ID\n   Gerald ,Hampton,82,Male,2582GABK\n   Yuuwa,Miyake,270,male,7951WVLW\n   Edyta,Majewska ,50,Female,775ANSID\n   '''))\n\n   errors = schema.validate(test_data)\n\n   for error in errors:\n       print(error)\n\nPandasSchema would then output\n\n.. code:: text\n\n   {row: 0, column: \"Given Name\"}: \"Gerald \" contains trailing whitespace\n   {row: 1, column: \"Age\"}: \"270\" was not in the range [0, 120)\n   {row: 1, column: \"Sex\"}: \"male\" is not in the list of legal options (Male, Female, Other)\n   {row: 2, column: \"Family Name\"}: \"Majewska \" contains trailing whitespace\n   {row: 2, column: \"Customer ID\"}: \"775ANSID\" does not match the pattern \"\\d{4}[A-Z]{4}\"\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A validation library for Pandas data frames using user-friendly schemas",
    "version": "0.3.6",
    "project_urls": {
        "Homepage": "https://github.com/TMiguelT/PandasSchema"
    },
    "split_keywords": [
        "pandas",
        "csv",
        "verification",
        "schema"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a589c2e12a52a7baa51fff89055b6c949bd7796ee4ba8432ec1af3c08e25d061",
                "md5": "4106f119a59d5bd8c8c84a99d25f697a",
                "sha256": "7497621cdf8c191fca1ef6ded9caa6f2153b220f120a2686d921f80c8031994d"
            },
            "downloads": -1,
            "filename": "pandas_schema-0.3.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4106f119a59d5bd8c8c84a99d25f697a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21710,
            "upload_time": "2022-02-18T23:51:26",
            "upload_time_iso_8601": "2022-02-18T23:51:26.780528Z",
            "url": "https://files.pythonhosted.org/packages/a5/89/c2e12a52a7baa51fff89055b6c949bd7796ee4ba8432ec1af3c08e25d061/pandas_schema-0.3.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "172ad302fd983cdf3fb9a3d24d981e4a3c7340994030c0c46b397b4d9db83bea",
                "md5": "c0296ef4881133432ceaf855851f973d",
                "sha256": "c6bfc52c4bae9cdd7420fbe8c4b0622b769457827c3fc819928405638caf605f"
            },
            "downloads": -1,
            "filename": "pandas_schema-0.3.6.tar.gz",
            "has_sig": false,
            "md5_digest": "c0296ef4881133432ceaf855851f973d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 26959,
            "upload_time": "2022-02-18T23:51:28",
            "upload_time_iso_8601": "2022-02-18T23:51:28.501883Z",
            "url": "https://files.pythonhosted.org/packages/17/2a/d302fd983cdf3fb9a3d24d981e4a3c7340994030c0c46b397b4d9db83bea/pandas_schema-0.3.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-02-18 23:51:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TMiguelT",
    "github_project": "PandasSchema",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pandas-schema"
}
        
Elapsed time: 0.30161s