Python Forum
Error Message: TypeError: unhashable type: 'set'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error Message: TypeError: unhashable type: 'set'
#1
Hello. I am attempting to compare two columns sar_details_sent_norm_trigrams_ and
caap_details_sent_norm_trigrams_ in a Pandas data frame. There are other columns as well, but these are the two I am comparing.

I'm essentially wanting to keep records where the text values for the two columns are the same.
I've executed a couple of approaches, however, I keep getting the following error message:

TypeError: unhashable type: 'set'

So, I either need to resolve why I am receiving this and fix it or try another approach, of course.
Any advice would be greatly appreciated.

Thanks.

Code snippet:

# Set with unique terms

df_sar['sar_details_sent_norm_trigrams_unique'] = df_sar['sar_details_sent_norm_trigrams_'].apply(lambda x: set([trigram for sent in x for trigram in sent]))

# Set with unique terms

df_caap['caap_details_sent_norm_trigrams_unique'] = df_caap['caap_details_sent_norm_trigrams_'].apply(lambda x: set([trigram for sent in x for trigram in sent]))



#Attempt 1: 

df_caap[df_caap.caap_details_sent_norm_trigrams_unique.isin(df_sar.sar_details_sent_norm_trigrams_unique)]


#Attempt 2:

set(df_caap.caap_details_sent_norm_trigrams_unique).intersection(set(df_sar.sar_details_sent_norm_trigrams_unique))
TypeError Traceback (most recent call last)
<ipython-input-171-2c2bb5551c7e> in <module>()
21 #set(df1.columns).intersection(set(df2.columns))
22
---> 23 set(df_caap.caap_details_sent_norm_trigrams_unique).intersection(set(df_sar.sar_details_sent_norm_trigrams_unique))

TypeError: unhashable type: 'set'
Reply


Messages In This Thread
Error Message: TypeError: unhashable type: 'set' - by twinpiques - May-06-2019, 12:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: unhashable type: 'Series' bongielondympofu 2 648 Mar-14-2024, 06:12 PM
Last Post: deanhystad
  [pandas] TypeError: list indices must be integers or slices, not str but type is int. cspower 4 972 Dec-30-2023, 09:38 AM
Last Post: Gribouillis
  GroupBy - Sum = Error [datetime64 type does not support sum operations] BSDevo 4 3,250 Oct-27-2023, 07:22 PM
Last Post: BSDevo
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,708 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Type error in Cross_val_score Vicral 0 1,862 Jul-20-2021, 12:18 PM
Last Post: Vicral
  type error array BrianPA 2 2,462 Jan-17-2021, 01:48 PM
Last Post: BrianPA
  Get error message in a GAN neural network tutorial jdude50 0 1,710 Oct-22-2020, 11:11 PM
Last Post: jdude50
  Error binding parameter 0 - probably unsupported type. illmattic 7 10,508 Jul-18-2020, 09:32 PM
Last Post: illmattic
  Series object error message abhaydd 1 4,957 Aug-11-2019, 01:29 AM
Last Post: boring_accountant
  Error Message - Akainu 2 3,330 May-24-2019, 09:09 PM
Last Post: Akainu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020