{"id":15041252,"url":"https://github.com/jlehrer1/sql-to-pandas","last_synced_at":"2026-01-07T05:03:39.056Z","repository":{"id":57470638,"uuid":"285394224","full_name":"jlehrer1/sql-to-pandas","owner":"jlehrer1","description":"Use SQL queries on Pandas DataFrames.","archived":false,"fork":false,"pushed_at":"2020-08-08T18:11:34.000Z","size":73,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T08:16:19.269Z","etag":null,"topics":["databases","pandas","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlehrer1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-05T20:13:52.000Z","updated_at":"2022-04-10T12:31:38.000Z","dependencies_parsed_at":"2022-09-26T17:31:38.795Z","dependency_job_id":null,"html_url":"https://github.com/jlehrer1/sql-to-pandas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlehrer1%2Fsql-to-pandas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlehrer1%2Fsql-to-pandas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlehrer1%2Fsql-to-pandas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlehrer1%2Fsql-to-pandas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlehrer1","download_url":"https://codeload.github.com/jlehrer1/sql-to-pandas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245814748,"owners_count":20676808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["databases","pandas","sql"],"created_at":"2024-09-24T20:45:48.976Z","updated_at":"2026-01-07T05:03:34.020Z","avatar_url":"https://github.com/jlehrer1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLtoPandas (WIP):\n\nUse SQL queries on Pandas DataFrames.\n\nAre you comfortable with SQL but not Pandas? Or maybe you're comfortable with Pandas but not SQL? Well, this library allows querying of Pandas DataFrames using SQL syntax. Hopefully it will let you learn SQL if you already understand Pandas, or learn how Pandas DataFrames behave if you already know SQL. \n\nUnlike [pandasql](https://github.com/yhat/pandasql), this package does not create a local sqlite3 data on the users computer and query from that. Rather, it converts SQL commands directly into pandas code.\n\n## Installation:\nRun `pip install sqltopandas==0.2` in your Python env to install using pip. It does require Python 3.8 for reasons outlined below.\n\n## Requirements: \nInstall all required dependencies through `pip` when this package is released, or generate the `conda` dev environment with `conda create --file environment.yml`, and activate with `conda active sqltopandas`. This *does* require Python 3.8 because getting variable literal names with f-string debugging is a critical part of the code infrastructure. I don't think there is a nice way to make that backwards compatible, sadly. \n\n## Usage:\nExample usage:\n```python3\n\u003e\u003e\u003e import sqltopandas\n\u003e\u003e\u003e spd = sqltopandas.SQLtoPD()\n\u003e\u003e\u003e df = pd.DataFrame(np.array([[1, 1, 3], [5, 5, 6], [7, 8, 9]]),columns=['a', 'b', 'c'])\n\u003e\u003e\u003e df\n   a  b  c\n0  1  1  3\n1  5  5  6\n2  7  8  9\n\u003e\u003e\u003e spd.parse(df, 'SELECT a, b FROM df')\n   a  b\n0  1  1\n1  5  5\n2  7  8\n\n\u003e\u003e\u003e spd.parse(df, \"\"\"SELECT a, b FROM df\n...                  WHERE a!=1; \"\"\")\n   a  b\n1  5  5\n2  7  8\n\n\u003e\u003e\u003e spd.parse(df, \"\"\"SELECT a, b, c FROM df;\n... \t\t            ORDER BY a DESC;\n...           \t\t   LIMIT 2;\"\"\")\n   a  b  c\n2  7  8  9\n1  5  5  6\n\n\u003e\u003e\u003e spd.parse(df, \"\"\"SELECT COUNT(a) FROM df\n...                  WHERE a=1 OR c=6; \"\"\")\n2\n```\n\n## Obvious edge cases \nDataFrame column names, as well as DataFrame names, cannot be SQL keywords. For example, a column name with \"SELECT\" or \"select\" will throw an error.\n\n## Syntactical Rules\nSQL tends to be quite lax with syntax. However, this library is not. *Each SQL statement must end with a `;`*. If it does not, it will not be parsed correctly. For example, `SELECT ... FROM ... WHERE;` is one statement, as we define which columns and rows to select, which DataFrame to select them from. Think of each statement as being a complete mathematical expression. `SELECT ... FROM ...; WHERE ...;` is an incorrect statement because `WHERE` does not have a reference. This rules may change as the package is updated, so visit [this](https://github.com/jlehrer1/sql-to-pandas) page for the most updated documentation.\n\n## Contributing:\nIf you have read this far I hope you've found this tool useful. I am always looking to learn more and develop as a programmer, so if you have any ideas or contributions, feel free to write a feature or pull request. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlehrer1%2Fsql-to-pandas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlehrer1%2Fsql-to-pandas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlehrer1%2Fsql-to-pandas/lists"}