category dictionary
moto {'motocycle':10, 'buy":8, 'motocompetition':7}
shopping {'buy':200, 'order':20, 'sale':30}
IT {'iphone':214, 'phone':1053, 'computer':809}
shopping {'zara':23, 'sale':18, 'sell':20}
IT {'lenovo':200, 'iphone':300, 'mac':200}
我需要GROUPBY類別和結果連擊字典,並選擇3個按鍵具有最大的價值。然後獲取數據幀,在列category
我有獨特的類別,並在列data
列我有列表中的鍵。
我知道,我可以使用Counter
連接字典,但我不知道,這是如何做類別。 慾望輸出
category data
moto ['motocycle', 'buy', 'motocompetition']
shopping ['buy', 'sale', 'zara']
IT ['phone', 'computer', 'iphone']
你可以給一個工作的例子嗎?到目前爲止你看到了什麼? – JMat
如果我只有字典,沒有數據框,我可以用'a = {1:2,2:5,6:9,u'cat':2} b = {1:4,4:2, 6:1,u'dog':11,u'cat':8} c = {5:2,7:1,u'dog':19} a =計數器(a) b =計數器(b ) c = Counter(c) d = a + b + c result = dict(d.most_common(3)) list = result.keys()'@JMat –