• Register
0 votes

Problem :

I want to get my python script to work. My input file consists of 3 columns: gene_ association_type, gene_name, and disease_name. But I keep facing the bekow error that says:

“Series objects are mutable and cannot be hashed”

Please let me know how can I fix the above error?

7 5 2
3,870 points

1 Answer

0 votes

Solution :

I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the very common problem with the people getting started. Directly coming to the point the gene_name[x] is the mutable object so you cannot hash it.. To use the object as the key in a dictionary, python needs to use the hash value, and that is the reason behind you facing above error.

More Details :

The Mutable objects are the objects whose value can be changed. For e.g., list is the mutable object, as you can append to it.And int is the immutable object, as you can't change it. When you do:

x = 5;
x = 3;

You are not changing the value of x but you are creating the new object and making x point to the value.

To resolve your error, you must use the immutable objects as the keys in your dictionary. For e.g.: tuplestringint.

9 7 4
38,600 points
Or you could add a __hash__() method to the object in question, as long as you're happy the hash created by it won't be modified within your code - potentially dangerous but has its uses

Related questions

0 votes
1 answer 3.9K views
Problem : I am using Pandas 0.20.3 in my python 3.X. I for the first time and want to add one column in a pandas data frame from the other pandas data frame. My both the data frame contains 51 rows. So I tried following code: class_df['phone']=group['phone ... when I type(group['phone']) it returns the pandas.core.series.Series Can anyone suggest me what changes I need to do to remove above error?
asked Nov 27, 2019 alecxe 7.5k points