网站更新内容:请访问: https://bigdata.ministep.cn/

Python将hive的table表转成dataframe

Python将hive的table表转成dataframe

一步到位,代码如下:

from pyhive import hive
import pandas as pd
def hive_read_sql(sql_code):
  connection = hive.Connection(host='10.111.3.61', port=10000, username='account')
  cur = connection.cursor()      
  cur.execute(sql_code)
  headers = [col[0] for col in cur.description]
  df= pd.DataFrame(cur.fetchall(), columns = headers)
  cur.close()
  return df

#sql = "select ds,type,user_id from test.table limit 10"
#df = hive_read_sql(sql)
#df.head()

 

 

 

mark

说明:链接中中未写数据库,由于存在跨库问题,在写HQL时候,默认自己带上库名即可;

posted @ 2022-02-09 19:50  ministep88  阅读(405)  评论(0编辑  收藏  举报
网站更新内容:请访问:https://bigdata.ministep.cn/