{ "info": { "author": "Ryoji Ishii", "author_email": "airtoxin@icloud.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: SQL", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "pysqldf\n=======\n\n|Build Status| |PyPI Version| |PyPI Monthly Downloads| |PyPI License|\n\n``pysqldf`` allows you to query ``pandas`` DataFrames using SQL syntax.\nIt works similarly to ``sqldf`` in R. ``pysqldf`` seeks to provide a\nmore familiar way of manipulating and cleaning data for people new to\nPython or ``pandas``.\n\nInstallation\n------------\n\n``$ pip install pysqldf``\n\nBasics\n------\n\nThe main class in pysqldf is ``SQLDF``. ``SQLDF`` accepts 1 enviroment\nvariable sets or more parametrs in constructor. - an set of\nsession/environment variables (dictionary of valiables, ``locals()`` or\n``globals()``) - temporary file type - user defined functions - user\ndefined aggregate functions\n\n``pysqldf`` uses `SQLite syntax `__.\nAny convertable data to ``pandas`` DataFrames will be automatically\ndetected by ``pysqldf``. You can query them as you would any regular SQL\ntable.\n\n.. code:: python\n\n $ python\n >>> from pysqldf import SQLDF, load_meat, load_births\n >>> sqldf = SQLDF(globals())\n >>> meat = load_meat()\n >>> births = load_births()\n >>> print sqldf.execute(\"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\n >>> q = \"SELECT m.date, m.beef, b.births FROM meat m INNER JOIN births b ON m.date = b.date;\"\n >>> print sqldf.execute(q).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 strftime('%Y', date) AS year, SUM(beef) AS beef_total FROM meat GROUP BY year;\"\n >>> print sqldf.execute(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\nuser defined functions and user defined aggregate functions also\nsupported.\n\n.. code:: python\n\n $ python\n >>> from pysqldf import SQLDF, load_iris\n >>> import math\n >>> import numpy\n >>> ceil = lambda x: math.ceil(x)\n >>> udfs = { \"ceil\": lambda x: math.ceil(x) }\n >>> udafs = { \"variance\": lambda values: numpy.var(values) }\n >>> # or you can also define aggregation function as class\n >>> # class variance(object):\n ... # def __init__(self):\n ... # self.a = []\n ... # def step(self, x):\n ... # self.a.append(x)\n ... # def finalize(self):\n ... # return numpy.var(self.a)\n ...\n >>> # udafs={ \"variance\": variance }\n >>> iris = load_iris()\n >>> sqldf = SQLDF(globals(), udfs=udfs, udafs=udafs)\n >>> sqldf.execute(\"\"\"\n SELECT\n ceil(sepal_length) AS sepal_length,\n ceil(sepal_width) AS sepal_width,\n ceil(petal_length) AS petal_length,\n ceil(petal_width) AS petal_width,\n species\n FROM iris;\n \"\"\").head()\n sepal_length sepal_width petal_length petal_width species\n 0 6 4 2 1 Iris-setosa\n 1 5 3 2 1 Iris-setosa\n 2 5 4 2 1 Iris-setosa\n 3 5 4 2 1 Iris-setosa\n 4 5 4 2 1 Iris-setosa\n >>> sqldf.execute(\"SELECT species, variance(sepal_width) AS var FROM iris GROUP BY species;\")\n species var\n 0 Iris-setosa 0.142276\n 1 Iris-versicolor 0.096500\n 2 Iris-virginica 0.101924\n\nDocuments\n---------\n\n``SQLDF(env, inmemory=True, udfs={}, udafs={})``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``env``: variable mapping dictionary of sql executed enviroment. key is\nsql variable name and value is your program variable. ``locals()`` or\n``globals()`` is used for simple assign.\n\n``inmemory``: sqlite db option.\n\n``udfs``: dictionary of user defined functions. dictionary key is\nfunction name, dictionary value is function. see `sqlite3\ndocument `__\n\n``udafs``: dictionary of user defined aggregate functions. dictionary\nkey is function name, dictionary value is aggregate function or class.\nIf value is function, function gets one argument that is list of column\nvalues and it should return aggregated a value. Another case(value is\nclass), see `sqlite3\ndocument `__.\n\n``load_iris()``, ``load_meat()``, ``load_births()``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nload example DataFrame data.\n\n- iris: `data\n description `__\n- meat: `data\n description `__\n- births: `data\n description `__\n\n.. |Build Status| image:: https://travis-ci.org/airtoxin/pysqldf.svg\n :target: https://travis-ci.org/airtoxin/pysqldf\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/pysqldf.svg\n :target: https://pypi.python.org/pypi/pysqldf\n.. |PyPI Monthly Downloads| image:: https://img.shields.io/pypi/dm/pysqldf.svg\n :target: https://pypi.python.org/pypi/pysqldf\n.. |PyPI License| image:: https://img.shields.io/pypi/l/pysqldf.svg\n :target: https://pypi.python.org/pypi/pysqldf", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/airtoxin/pysqldf", "keywords": "sqldf pandas dataframe sql pandasql", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pysqldf", "package_url": "https://pypi.org/project/pysqldf/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pysqldf/", "project_urls": { "Homepage": "https://github.com/airtoxin/pysqldf" }, "release_url": "https://pypi.org/project/pysqldf/1.2.3/", "requires_dist": [ "pandas" ], "requires_python": "", "summary": "sqldf for pandas", "version": "1.2.3" }, "last_serial": 1767597, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "9c8402b95a82053bf48b27f151f27a4f", "sha256": "876eeabedb209a4e8218155a5665cd1f81daf491d6f81dc0c83a95c2a2f775fa" }, "downloads": -1, "filename": "pysqldf-1.0.0.tar.gz", "has_sig": false, "md5_digest": "9c8402b95a82053bf48b27f151f27a4f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24981, "upload_time": "2015-09-21T10:24:41", "url": "https://files.pythonhosted.org/packages/2d/03/e59d57ea9d931c30aef7f968edb2d0e72acb80b645fbb61b82dd65df2721/pysqldf-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "f97509c0e829e7c7d8e86f9501af8eac", "sha256": "ba152c0d485ba1a81ade8efbc227f6d0416d433ceef58f835bb4599b092278ef" }, "downloads": -1, "filename": "pysqldf-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f97509c0e829e7c7d8e86f9501af8eac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28037, "upload_time": "2015-09-21T15:09:04", "url": "https://files.pythonhosted.org/packages/09/cd/d17266dc9ae66d401712a6336be05d9a28a05cac3d6a0a5b0aa33d59ccbc/pysqldf-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "ba07ab74e0992ed685c762920a77056b", "sha256": "8e978c2cec571668a71ad92e9eaff9d978a840abb2a538bc3cc97e4a87acd89f" }, "downloads": -1, "filename": "pysqldf-1.2.0.tar.gz", "has_sig": false, "md5_digest": "ba07ab74e0992ed685c762920a77056b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29922, "upload_time": "2015-09-23T10:47:25", "url": "https://files.pythonhosted.org/packages/27/c1/46bf4ccaa14cfd66ce9629155a8b7e4e5da2eb21a1cfef6229b706deb3b1/pysqldf-1.2.0.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "b8f0f9bf1e9cec212b7b1f4ba9cd5201", "sha256": "121efcad141bb1933405215742c47031a93341f7303427c6d32f4964b116aec9" }, "downloads": -1, "filename": "pysqldf-1.2.1.tar.gz", "has_sig": false, "md5_digest": "b8f0f9bf1e9cec212b7b1f4ba9cd5201", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30603, "upload_time": "2015-10-06T11:08:30", "url": "https://files.pythonhosted.org/packages/48/d4/64d0c7f77938957dfe7ad2048df0cb11e74b85b2925494a3421c1702d058/pysqldf-1.2.1.tar.gz" } ], "1.2.2": [ { "comment_text": "", "digests": { "md5": "a7d1310eda02e350564788e26ed4d497", "sha256": "3c303303eeed8b83149853a8a86324eb231ac2382439a601ba904b72c45184db" }, "downloads": -1, "filename": "pysqldf-1.2.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a7d1310eda02e350564788e26ed4d497", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 27414, "upload_time": "2015-10-13T23:51:04", "url": "https://files.pythonhosted.org/packages/1a/76/3fe9842339d9c26904761c668662930152f79c046b7882ef056eb4acfe37/pysqldf-1.2.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a6a7b8d7091ca4c24ed800bc25e607f6", "sha256": "147b0bdbe4fb9385185e9e77acdce18976cd399702443d6595f3b57d75894b35" }, "downloads": -1, "filename": "pysqldf-1.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a6a7b8d7091ca4c24ed800bc25e607f6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 27410, "upload_time": "2015-10-13T23:51:14", "url": "https://files.pythonhosted.org/packages/6a/bd/b1462a7bd4a8f2bd208f19dc35479b8526f1f693db30f64f4af4ea53f081/pysqldf-1.2.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "31e6b62e10bbf57e1a1d51cd31ea09d7", "sha256": "c20cfca30f54549e8f5e1201f4d5ddcefd518bd6a734d4f331de0a1701a2cd5f" }, "downloads": -1, "filename": "pysqldf-1.2.2.tar.gz", "has_sig": false, "md5_digest": "31e6b62e10bbf57e1a1d51cd31ea09d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30662, "upload_time": "2015-10-07T23:13:47", "url": "https://files.pythonhosted.org/packages/57/55/2cbacbf55832b99f1207681531ed7a88df663d6df5d2be61ed2aea9c44ee/pysqldf-1.2.2.tar.gz" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "32f3bf982cf0cb0168fa4080eefa2dcb", "sha256": "de405d5a6e2950fc376ccd00b2dfc4f0971cf63dc0fc237e1647a818a5761b82" }, "downloads": -1, "filename": "pysqldf-1.2.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "32f3bf982cf0cb0168fa4080eefa2dcb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 27414, "upload_time": "2015-10-13T23:51:23", "url": "https://files.pythonhosted.org/packages/12/a4/8c43cdf5880400969b778240b43ad1f492e841b2858faee2f097e7175cd0/pysqldf-1.2.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a35914a1e4fe21cb716fb792cf18129", "sha256": "d88e3b19b7cb570fee5c1c266557b680010d4a9eaf23c09ca28494469e01956e" }, "downloads": -1, "filename": "pysqldf-1.2.3.tar.gz", "has_sig": false, "md5_digest": "3a35914a1e4fe21cb716fb792cf18129", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30781, "upload_time": "2015-10-13T23:57:36", "url": "https://files.pythonhosted.org/packages/f8/57/d53fc768d8a3ed534cd670d033e342ce07b901f636491790a0c9fbb63743/pysqldf-1.2.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "32f3bf982cf0cb0168fa4080eefa2dcb", "sha256": "de405d5a6e2950fc376ccd00b2dfc4f0971cf63dc0fc237e1647a818a5761b82" }, "downloads": -1, "filename": "pysqldf-1.2.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "32f3bf982cf0cb0168fa4080eefa2dcb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 27414, "upload_time": "2015-10-13T23:51:23", "url": "https://files.pythonhosted.org/packages/12/a4/8c43cdf5880400969b778240b43ad1f492e841b2858faee2f097e7175cd0/pysqldf-1.2.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a35914a1e4fe21cb716fb792cf18129", "sha256": "d88e3b19b7cb570fee5c1c266557b680010d4a9eaf23c09ca28494469e01956e" }, "downloads": -1, "filename": "pysqldf-1.2.3.tar.gz", "has_sig": false, "md5_digest": "3a35914a1e4fe21cb716fb792cf18129", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30781, "upload_time": "2015-10-13T23:57:36", "url": "https://files.pythonhosted.org/packages/f8/57/d53fc768d8a3ed534cd670d033e342ce07b901f636491790a0c9fbb63743/pysqldf-1.2.3.tar.gz" } ] }