美文网首页python的坑
【python】读取数据库

【python】读取数据库

作者: MichalLiu | 来源:发表于2019-10-10 16:09 被阅读0次

1.连接Hive

import pandas as pd
from sqlalchemy.engine import create_engine
 
# 准备语句(不能带分号)
sql = '''
        SELECT * FROM db.test LIMIT 10
      '''
 
presto_engine = create_engine('presto://110.120.119.115:8866/hive')
 
# 获取数据
df = pd.read_sql(sql, presto_engine)
print(df)
df.to_csv(r'C:\Users\liuzw3\Desktop\output_files.csv',index=False,encoding='utf-8')

相关文章

网友评论

    本文标题:【python】读取数据库

    本文链接:https://www.haomeiwen.com/subject/mtrapctx.html