为什么我的一段代码给我“数据帧”对象是可变?

问题描述 投票:1回答:1

请检查下面的错误......一些值出现在commonlist所以,我不希望它包含commonlist df_head的价值......或者可以说df_head = df_head - commonlist

commonlist =df_head[df_head['Name'].isin(common)]
df_head not in commonlist

错误出现在这里

TypeError                                 Traceback (most recent call last)
<ipython-input-16-ff85aff2f182> in <module>
----> 1 df_head not in commonlist

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __contains__(self, key)
   1520     def __contains__(self, key):
   1521         """True if the key is in the info axis"""
-> 1522         return key in self._info_axis
   1523 
   1524     @property

~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in __contains__(self, key)
   2033     @Appender(_index_shared_docs['__contains__'] % _index_doc_kwargs)
   2034     def __contains__(self, key):
-> 2035         hash(key)
   2036         try:
   2037             return key in self._engine

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __hash__(self)
   1490     def __hash__(self):
   1491         raise TypeError('{0!r} objects are mutable, thus they cannot be'
-> 1492                         ' hashed'.format(self.__class__.__name__))
   1493 
   1494     def __iter__(self):

TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
python pandas
1个回答
1
投票

做就是了 :

df_head[~df_head['Name'].isin(common)]

~将否定了这df_head['Name'].isin(common)值。

commonlist实际上是不需要为了这个目的,直到你想将它们存储其他原因。

© www.soinside.com 2019 - 2024. All rights reserved.