abhijithneilabraham/tableQA
abhijithneilabraham/tableQA has 320 GitHub stars and 45 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-12 06:53 UTC. Last push 2023-11-29.
AI Tool for querying natural language on tabular data.
可以做什么
- Supports detection from multiple csvs (csvs can also be read from Amazon s3)
- Supports FuzzyString implementation. i.e, incomplete column values in query can be automatically detected and filled in the query.
- Supports Databases - SQLite, Postgresql, MySQL, Amazon RDS (Postgresql, MySQL).
- Open-Domain, No training required.
实测星标增长
- 24小时
- 0
- 7天
- 更新延迟
- 15天
- 更新延迟
- 1个月
- 更新延迟
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文tableQA
AI Tool for querying natural language on tabular data.Built using QA models from transformers.
This work is described in the following paper:
TableQuery: Querying tabular data with natural language, by Abhijith Neil Abraham, Fariz Rahman and Damanpreet Kaur.
If you use TableQA, please cite the paper.
Here is a detailed blog to understand how this works.
A tabular data can be:
- Dataframes
- CSV files
Features
- Supports detection from multiple csvs (csvs can also be read from Amazon s3)
- Supports FuzzyString implementation. i.e, incomplete column values in query can be automatically detected and filled in the query.
- Supports Databases - SQLite, Postgresql, MySQL, Amazon RDS (Postgresql, MySQL).
- Open-Domain, No training required.
- Add manual schema for customized experience
- Auto-generate schemas in case schema not provided
- Data visualisations.
Supported operations.
- SELECT
- one column
- multiple columns
- all columns
- aggregate functions
- distinct select
- count-select
- sum-select
- avg-select
- min-select
- max-select
- WHERE
- one condition
- multiple conditions
- operators
- equal operator
- greater-than operator
- less-than operator
- between operator
Configuration:
install via pip:
pip install tableqa
installing from source:
git clone https://github.com/abhijithneilabraham/tableQA
cd tableqa
python setup.py install
Quickstart
Do sample query
from tableqa.agent import Agent
agent=Agent(df) #input your dataframe
response=agent.query_db("Your question here")
print(response)
Get an SQL query from the question
sql=agent.get_query("Your question here")
print(sql) #returns an sql query
Adding Manual schema
Schema Format:
{
"name": DATABASE NAME,
"keywords":[DATABASE KEYWORDS],
"columns":
[
{
"name": COLUMN 1 NAME,
"mapping":{
CATEGORY 1: [CATEGORY 1 KEYWORDS],
CATEGORY 2: [CATEGORY 2 KEYWORDS]
}
},
{
"name": COLUMN 2 NAME,
"keywords": [COLUMN 2 KEYWORDS]
},
{
"name": "COLUMN 3 NAME",
"keywords": [COLUMN 3 KEYWORDS],
"summable":"True"
}
]
}
- Mappings are for those columns whose values have only few distinct classes.
- Include only the column names which need to have manual keywords or mappings.Rest will will be autogenerated.
summableis included for Numeric Type columns whose values are already count representations. Eg.Death Count,Casesetc. consists values which already represent a count.
Example (with manual schema):
Database query
- Default Database - SQLite (File-based database, does not require creation of a separate connection.)
from tableqa.agent import Agent
agent=Agent(df,schema) #pass the dataframe and schema objects
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
- To use PostgreSQL, you must have a postgresql server installed and running on your local. To download postgresql, visit the page.
from tableqa.agent import Agent
agent = Agent(df, schema_file, 'postgres', username='username', password='password', database='DBname', host='localhost', port=5432, aws_db=False)
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
- To use MySQL, you must have a mysql server installed and running on your local. To download mysql, visit the page.
from tableqa.agent import Agent
agent = Agent(df, schema_file, 'mysql', username='username', password='password', database='DBname', host='localhost', port=5432, aws_db=False)
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
- To use PostgreSQL or MySQL on Amazon RDS, you must create a database on Amazon RDS. The RDS must be in public subnet with security groups allowing connections from outside of AWS.
Refer to step 1 in the document to create a mysql db instance on Amazon RDS. Same steps can be followed for creating a PostgreSQL db instance by selecting PostgreSQL in the Engine tab. Obtain the username, password, database, endpoint, and port from your database connection details on Amazon RDS.
from tableqa.agent import Agent
agent = Agent(df, schema_file, 'postgres', username='Master username', password='Master password', database='DB name', host='Endpoint', port='Port', aws_db=True)
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
SQL query
sql=agent.get_query("How many people died of stomach cancer in 2011")
print(sql)
#sql query: SELECT SUM(Death_Count) FROM cancer_death WHERE Cancer_site = "Stomach" AND Year = "2011"
Multiple CSVs
- Pass the absolute path of the directories containing the csvs and schemas respectively. Refer cleaned_data and schema for examples.
Example
- Read CSV and Schema from local machine-
csv_path="/content/tableQA/tableqa/cleaned_data"
schema_path="/content/tableQA/tableqa/schema"
agent=Agent(csv_path,schema_path)
- Read CSV and schema files from Amazon s3 -
- Create a bucket on Amazon s3.
- Upload objects to the bucket.
- Create an IAM user and provide it access to read files from Amazon s3 storage.
- Obtain the access key and secret access key for the user and pass it as an argument to the agent.
csv_path="s3://{bucket}/cleaned_data"
schema_path="s3://{bucket}/schema"
agent = Agent(csv_path, schema_path, aws_s3=True, access_key_id=access_key_id, secret_access_key=secret_access_key)
Join us
Join our workspace:Slack
探索相关项目
Asabeneh/30-Days-Of-Python
30 Days of Python 编程挑战是一份循序渐进的指南,用于在 30 天内学习 Python 编程语言。这项挑战可能需要超过 100 天。请按自己的节奏进行。这些视频或许也有帮助:https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,618 星标grafana/grafana
开放且可组合的可观测性与数据可视化平台。可对来自 Prometheus、Loki、Elasticsearch、InfluxDB、Postgres 等众多数据源的指标、日志和追踪进行可视化。
77,859 星标redis/redis
对于正在构建实时数据驱动应用的开发者而言,Redis 是首选、速度最快且功能最丰富的缓存、数据结构服务器和文档与向量查询引擎。
77,472 星标apache/superset
Apache Superset 是一个数据可视化与数据探索平台
75,495 星标