python操作HBase

1.安装happybase和thrift

pip install happybase
pip install thrift

2.启动hbase的thrift进程,并指定端口9090

hbase-daemon.sh start thrift -p 9090

3.操作HBase

import happybase

connection = happybase.Connection(host='hadoop10', port=9090)
table = connection.table("testhb:t_goods")

# 增改
table.put('1001', {'info:name': 'xiaomi14', 'info:price': '5999'})
table.put('1002', {'info:name': 'iphone15', 'info:price': '8999'})
table.put('1003', {'info:name': 'OPPOFindx6', 'info:price': '4766'})

# 查指定行
row = table.row('1001')
print(row)

# 查看所有数据
for key, value in table.scan():
    print(key, value)

# 删除一行
table.delete('1001')
table.delete('1003', columns=['info'])
table.delete('1002', columns=['info:name', 'info:price'])

# 删除指定列
table.delete('1003', columns=['info:name'])

connection.close()

你可能感兴趣的:(大数据,Python,hbase,数据库,大数据)