pandasql


Namepandasql JSON
Version 0.7.3 PyPI version JSON
download
home_pagehttps://github.com/yhat/pandasql/
Summarysqldf for pandas
upload_time2016-04-20 21:52:47
maintainerNone
docs_urlNone
authorGreg Lamp
requires_pythonNone
licenseCopyright (c) 2013 Yhat, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pandasql
========

``pandasql`` allows you to query ``pandas`` DataFrames using SQL syntax.
It works similarly to ``sqldf`` in R. ``pandasql`` seeks to provide a
more familiar way of manipulating and cleaning data for people new to
Python or ``pandas``.

Installation
^^^^^^^^^^^^

::

    $ pip install -U pandasql

Basics
^^^^^^

The main function used in pandasql is ``sqldf``. ``sqldf`` accepts 2
parametrs - a sql query string - an set of session/environment variables
(``locals()`` or ``globals()``)

Specifying ``locals()`` or ``globals()`` can get tedious. You can
defined a short helper function to fix this.

::

    from pandasql import sqldf
    pysqldf = lambda q: sqldf(q, globals())

Querying
^^^^^^^^

``pandasql`` uses `SQLite syntax <http://www.sqlite.org/lang.html>`__.
Any ``pandas`` dataframes will be automatically detected by
``pandasql``. You can query them as you would any regular SQL table.

::

    $ python
    >>> from pandasql import sqldf, load_meat, load_births
    >>> pysqldf = lambda q: sqldf(q, globals())
    >>> meat = load_meat()
    >>> births = load_births()
    >>> print pysqldf("SELECT * FROM meat LIMIT 10;").head()
                      date  beef  veal  pork  lamb_and_mutton broilers other_chicken turkey
    0  1944-01-01 00:00:00   751    85  1280               89     None          None   None
    1  1944-02-01 00:00:00   713    77  1169               72     None          None   None
    2  1944-03-01 00:00:00   741    90  1128               75     None          None   None
    3  1944-04-01 00:00:00   650    89   978               66     None          None   None
    4  1944-05-01 00:00:00   681   106  1029               78     None          None   None

joins and aggregations are also supported

::

    >>> q = """SELECT
            m.date, m.beef, b.births
         FROM
            meats m
         INNER JOIN
            births b
               ON m.date = b.date;"""
    >>> joined = pyqldf(q)
    >>> print joined.head()
                        date    beef  births
    403  2012-07-01 00:00:00  2200.8  368450
    404  2012-08-01 00:00:00  2367.5  359554
    405  2012-09-01 00:00:00  2016.0  361922
    406  2012-10-01 00:00:00  2343.7  347625
    407  2012-11-01 00:00:00  2206.6  320195

    >>> q = "select
               strftime('%Y', date) as year
               , SUM(beef) as beef_total
               FROM
                  meat
               GROUP BY
                  year;"
    >>> print pysqldf(q).head()
       year  beef_total
    0  1944        8801
    1  1945        9936
    2  1946        9010
    3  1947       10096
    4  1948        8766

More information and code samples available in the
`examples <https://github.com/yhat/pandasql/blob/master/examples/demo.py>`__
folder or on `our
blog <http://blog.yhathq.com/posts/pandasql-sql-for-pandas-dataframes.html>`__.

|Analytics|

.. |Analytics| image:: https://ga-beacon.appspot.com/UA-46996803-1/pandasql/README.md
   :target: https://github.com/yhat/pandasql
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yhat/pandasql/",
    "name": "pandasql",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Greg Lamp",
    "author_email": "greg@yhathq.com",
    "download_url": "https://files.pythonhosted.org/packages/6b/c4/ee4096ffa2eeeca0c749b26f0371bd26aa5c8b611c43de99a4f86d3de0a7/pandasql-0.7.3.tar.gz",
    "platform": "UNKNOWN",
    "description": "pandasql\n========\n\n``pandasql`` allows you to query ``pandas`` DataFrames using SQL syntax.\nIt works similarly to ``sqldf`` in R. ``pandasql`` seeks to provide a\nmore familiar way of manipulating and cleaning data for people new to\nPython or ``pandas``.\n\nInstallation\n^^^^^^^^^^^^\n\n::\n\n    $ pip install -U pandasql\n\nBasics\n^^^^^^\n\nThe main function used in pandasql is ``sqldf``. ``sqldf`` accepts 2\nparametrs - a sql query string - an set of session/environment variables\n(``locals()`` or ``globals()``)\n\nSpecifying ``locals()`` or ``globals()`` can get tedious. You can\ndefined a short helper function to fix this.\n\n::\n\n    from pandasql import sqldf\n    pysqldf = lambda q: sqldf(q, globals())\n\nQuerying\n^^^^^^^^\n\n``pandasql`` uses `SQLite syntax <http://www.sqlite.org/lang.html>`__.\nAny ``pandas`` dataframes will be automatically detected by\n``pandasql``. You can query them as you would any regular SQL table.\n\n::\n\n    $ python\n    >>> from pandasql import sqldf, load_meat, load_births\n    >>> pysqldf = lambda q: sqldf(q, globals())\n    >>> meat = load_meat()\n    >>> births = load_births()\n    >>> print pysqldf(\"SELECT * FROM meat LIMIT 10;\").head()\n                      date  beef  veal  pork  lamb_and_mutton broilers other_chicken turkey\n    0  1944-01-01 00:00:00   751    85  1280               89     None          None   None\n    1  1944-02-01 00:00:00   713    77  1169               72     None          None   None\n    2  1944-03-01 00:00:00   741    90  1128               75     None          None   None\n    3  1944-04-01 00:00:00   650    89   978               66     None          None   None\n    4  1944-05-01 00:00:00   681   106  1029               78     None          None   None\n\njoins and aggregations are also supported\n\n::\n\n    >>> q = \"\"\"SELECT\n            m.date, m.beef, b.births\n         FROM\n            meats m\n         INNER JOIN\n            births b\n               ON m.date = b.date;\"\"\"\n    >>> joined = pyqldf(q)\n    >>> print joined.head()\n                        date    beef  births\n    403  2012-07-01 00:00:00  2200.8  368450\n    404  2012-08-01 00:00:00  2367.5  359554\n    405  2012-09-01 00:00:00  2016.0  361922\n    406  2012-10-01 00:00:00  2343.7  347625\n    407  2012-11-01 00:00:00  2206.6  320195\n\n    >>> q = \"select\n               strftime('%Y', date) as year\n               , SUM(beef) as beef_total\n               FROM\n                  meat\n               GROUP BY\n                  year;\"\n    >>> print pysqldf(q).head()\n       year  beef_total\n    0  1944        8801\n    1  1945        9936\n    2  1946        9010\n    3  1947       10096\n    4  1948        8766\n\nMore information and code samples available in the\n`examples <https://github.com/yhat/pandasql/blob/master/examples/demo.py>`__\nfolder or on `our\nblog <http://blog.yhathq.com/posts/pandasql-sql-for-pandas-dataframes.html>`__.\n\n|Analytics|\n\n.. |Analytics| image:: https://ga-beacon.appspot.com/UA-46996803-1/pandasql/README.md\n   :target: https://github.com/yhat/pandasql",
    "bugtrack_url": null,
    "license": "Copyright (c) 2013 Yhat, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "sqldf for pandas",
    "version": "0.7.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0101b2b422d6b3fc34a6b06bfcc41b954f7a71005d1318ed59e123d5ae70d5a",
                "md5": "1a87b7250e14c52153be1f5d4464ca8f",
                "sha256": "75f08c5cdfd19f61ceed8c38a6ac138c353776ad3be8e015edcee977c2299aad"
            },
            "downloads": -1,
            "filename": "pandasql-0.7.3-py2.7.egg",
            "has_sig": false,
            "md5_digest": "1a87b7250e14c52153be1f5d4464ca8f",
            "packagetype": "bdist_egg",
            "python_version": "2.7",
            "requires_python": null,
            "size": 36287,
            "upload_time": "2016-04-20T21:52:36",
            "upload_time_iso_8601": "2016-04-20T21:52:36.708205Z",
            "url": "https://files.pythonhosted.org/packages/c0/10/1b2b422d6b3fc34a6b06bfcc41b954f7a71005d1318ed59e123d5ae70d5a/pandasql-0.7.3-py2.7.egg",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6bc4ee4096ffa2eeeca0c749b26f0371bd26aa5c8b611c43de99a4f86d3de0a7",
                "md5": "6bfca10a075d587d0da0c3ada496d613",
                "sha256": "1eb248869086435a7d85281ebd9fe525d69d9d954a0dceb854f71a8d0fd8de69"
            },
            "downloads": -1,
            "filename": "pandasql-0.7.3.tar.gz",
            "has_sig": false,
            "md5_digest": "6bfca10a075d587d0da0c3ada496d613",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 26702,
            "upload_time": "2016-04-20T21:52:47",
            "upload_time_iso_8601": "2016-04-20T21:52:47.564507Z",
            "url": "https://files.pythonhosted.org/packages/6b/c4/ee4096ffa2eeeca0c749b26f0371bd26aa5c8b611c43de99a4f86d3de0a7/pandasql-0.7.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2016-04-20 21:52:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "yhat",
    "github_project": "pandasql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pandasql"
}
        
Elapsed time: 0.05056s