df ['X'].unique()和TypeError:无法散列的类型:'numpy.ndarray' [英] df ['X'].unique() and TypeError: unhashable type: 'numpy.ndarray'
本文介绍了df ['X'].unique()和TypeError:无法散列的类型:'numpy.ndarray'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部
我在数据框中有一个看起来像这样的列:
I have a column in a dataframe that looks like this:
allHoldingsFund['BrokerMixed']
Out[419]:
78 ML
81 CITI
92 ML
173 CITI
235 ML
262 ML
264 ML
25617 GS
25621 CITI
25644 CITI
25723 GS
25778 CITI
25786 CITI
25793 GS
25797 CITI
Name: BrokerMixed, Length: 2554, dtype: object
尽管该列是一个对象.我无法按该列分组,甚至无法提取该列的唯一值.例如,当我这样做时:
Although the column is an object. I am not able to group by that column or even extract the unique values of that column. For example when I do:
allHoldingsFund['BrokerMixed'].unique()
我得到一个错误
uniques = table.unique(values)
File "pandas/_libs/hashtable_class_helper.pxi", line 1340, in pandas._libs.hashtable.PyObjectHashTable.unique
TypeError: unhashable type: 'numpy.ndarray'
分组时也会出现错误.
欢迎任何帮助.谢谢
推荐答案
首先,我建议您检查一下column
中的type
.您可以尝试如下
First I would suggest you to check what's type
of your column
. You may try as follows
print (type(allHoldingsFund['BrokerMixed']))
如果这是dataframe series
,则可以尝试
allHoldingsFund['BrokerMixed'].reset_index()['BrokerMixed'].unique()
,然后检查它是否适合您.
and check if this works for you.
EDIT 2020
:获得唯一和提及的答案的方法使用Python 3获取相同的结果
EDIT 2020
: Your way to get unique and mentioned answers fetch same results using Python 3
这篇关于df ['X'].unique()和TypeError:无法散列的类型:'numpy.ndarray'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文