簡體   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