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