使用pandas处理HBase数据

原创
2017/06/29 09:21
阅读数 244
import happybase
from pandas import DataFrame
def hbase_connect(table_name):
    connection = happybase.Connection('localhost', autoconnect=False)
    connection.open()
    table = connection.table(table_name)
    return table
    
table = hbase_connect('live_gift')
data = table.scan(columns=[b'g:user_id', b'g:gift_price'],  limit=10)

my_generator = ((d['g:user_id'], d['g:gift_price']) for k, d in data)
mylist = list(my_generator)
mydata = DataFrame(mylist)

column_name = ['user_id', 'gift_price']
mydata.columns = column_name
mydata['gift_price'] = mydata['gift_price'].apply(int)
mydata['gift_price'].sum()

####################################
import time
def Timestamp_conversion(date):
    timeArray = time.strptime(date, "%Y-%m-%d %H:%M:%S")
    timestamp = int(time.mktime(timeArray))
    return timestamp
    

def date_conversion(timestamp):
    time_local = time.localtime(timestamp)
    date = time.strftime("%Y-%m-%d %H:%M:%S",time_local)
    return date
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部