In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.