使pandas数据帧中不可损坏的值成为散列值
hashable-df的Python项目详细描述
哈希表
如果您曾经尝试在Pandas数据帧中使用原生python对象, 您可能遇到了类似的问题:
df=pd.DataFrame({"A":[1,2,3,4],"B":["a","b","c","d"],"C":[[1,2,3],[1,2],[1,2,3],4],"D":[{1:1,2:2},{1:1,3:3},{1:1,4:4},{1:1,2:2}],"E":[[{1:{2:2}},{2:{3:3}}],[{1:{2:2}},{2:{3:3}}],[{1:{2:2}},{2:{3:3}}],[{1:{2:2}},{2:{3:3}}]]})df['C'].unique()
TypeError: unhashable type: 'list'
这是由数据帧单元中不可损坏的值引起的。在
这个小库有助于解决这一问题:
^{pr2}$返回
array([[{1: {2: 2}}, {2: {3: 3}}]], dtype=object)
- 项目
标签: