Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use Python to connect to all databases for data analysis

Shulou Source: shulou.com Published: 2022-05-31 21:36:22 09月30日 Update

This article mainly explains "how to use Python to connect all databases to do data analysis", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Python to connect to all databases for data analysis.

For most sqlboys and sqlgirls, all I care about is that my sql is submitted to the above database and returned to me as a dataframe for pandas. So the necessary input includes sql and database connection information (including address, port, account password).

From sqlachemy import create_engine import pandas as pd # Database connection address engine = create_engine ("mysql://root:123456@127.0.0.1:3306/database") # sql sql = "select * from users limit 10" df = pd.read_sql_query (sql, engine) presto# presto uri = "presto://username:password@127.0.0.1:8080/database?source=pyhive" sql = "select * from users limit 10" df = pd.read_sql_query (sql Create_engine (uri)) mysql# mysql uri = "mysql://root:123456@127.0.0.1:3306/database" sql = "select * from users limit 10" df = pd.read_sql_query (sql, create_engine (uri)) druid# druid uri = "druid://:@:/druid/v2/sql" sql = "select count (*) from users where _ time > TIME_SHIFT...." Df = pd.read_sql_query (sql, create_engine (uri))

More database connection methods:

Basically all the databases on the market, as long as the database supports sqlalchemy dialect and the corresponding python driver, can follow the above routine to operate without a brain. It's simple and easy.

The core needs only one line of code:

Df = pd.read_sql_query (sql, create_engine (uri)) at this point, I believe you have a deeper understanding of "how to use Python to connect to all databases for data analysis". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Data database data analysis analysis content address more learning query practical deeper worry-free necessary one line code information interest most routines practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Microsoft vpn Linux