0

This code makes a connection to hbase, and then prints the result of a given row. But the result is printed like this:

import happybase

    connection = happybase.Connection('MacBook-Air.local')
    table = connection.table('twitter_db')
    row = table.row('2018-09-21 11:55:24')
    print(row)

But the result is printed like this:

{'Hashtag:#AFDs': '1', 'Hashtag:#Job': '1', 'Hashtag:#pumpkinpoundcake': '1', 'Lang:und': '81', 'Lang:pt ': '17', 'Hashtag:#InsomniaInFourWords': '2', 'Hashtag:#thegreatindianbooktour': '1', 'Hashtag:#pdx911': '2', 'Hashtag:#US': '1', 'Lang:en ': '246', 'Lang:es ': '31', 'Hashtag:#travelling': '1', 'Hashtag:#prohibition': '1', 'Hashtag:#FF': '2', 'Lang:in ': '15'}

I would like to print on one side all the hashtags with their relative numbers in ascending order and by one or all the languages with their relative numbers in ascending order. For example:

'Hashtag:#FF': '2'
'Hashtag:#AFDs': '1'
'Hashtag:#Job': '1'
.........

----------------
'Lang:en ': '246'
'Lang:und': '81'
'Lang:es ': '31'
.......

For example I could create a method but how?

Danny
  • 165
  • 1
  • 12
  • Ok, so it returns a dictionary. Have you tried iterating through the keys and values and printing them? – roganjosh Sep 21 '18 at 12:09
  • Take a look at sorting dictionaries: https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value. You'd need to use OrderedDict because dictionaries aren't by nature ordered. You'd also need to figure out how to handle the fact that you have both Lang and Hashtag in the same dictionary assuming you are just going to be sorting on the value of the keys regardless of what the key is. – tlm Sep 21 '18 at 12:22

0 Answers0