繁体   English   中英

pandas.unique() TypeError: unhashable type: 'list'

[英]pandas .unique() TypeError: unhashable type: 'list'

我有一个 pandas dataframe 列,其中包含 SQL 的“标签”,我很想知道这些标签的唯一值是什么。

对于我的 pandas dataframe 列,如果我使用tags.m_tags.unique()这将通过错误TypeError: unhashable type: 'list'

手动查看列表格式的数据m_tags如下所示:

[reheat, cmd]
[discharge, temp, air, sensor]
[flow, air, sensor]
[zone, temp, air, sensor]

有人知道如何解决这个问题吗?

只需使用explode()方法和chain unique()方法:

result=tags['m_tags'].explode().unique()

现在,如果您打印result ,您将获得所需的 output

编辑:如果你有字典,那么使用:

result=df['tags'].apply(lambda x:list(x.values())).explode().unique()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM