• 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

Please log in or register to answer this question.

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 213 views
0 votes
1 answer 15 views
0 votes
1 answer 5.1K 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
0 votes
1 answer 11 views
Problem: mutable exist, alterable don't. In Java, all strings are changeless. In your first model, you are changing the reference to the String , in this way allotting it the estimation of two different Strings joined: Why String Is Immutable? In Java, String is a final and immutable class, which makes it the most special
asked Nov 5, 2020 Mashhoodch 5.6k points
1 vote
2 answers 671 views
Problem : I am very new to the Node.js and I am having few issues. I am using the Node.js 4.10 and Express 2.4.3. While trying to execute my code I am receiving below error : Error: Can't render headers after they are sent to the client. ... , scope: 'offline_access,email,user_about_me,user_activities,manage_pages,publish_stream', failedUri: '/noauth' }) ])); realapp.use(realapp.router); }); . . .
asked Dec 12, 2019 alecxe 7.5k points
0 votes
1 answer 23 views
I have a data frame that looks something like this: defaultdict(<class 'list'>, {'XYF': TimeUS GyrX GyrY GyrZ AccX \ 0 207146570 0.000832914 0.001351716 -0.0004189798 -0.651183 1 207186671 0.001962787 0.001242457 -0.0001859666 -0.6423497 2 207226791 9.520243E-05 0. ... 1000000 This give me an error: TypeError: cannot convert the series to <class 'float'> I have no idea where to go from here.
asked Oct 25, 2020 psandprop 2.4k points
0 votes
2 answers 174 views
Problem : I am trying to import my project that I and my co-worker have been working on.. and keep getting below error after I select&mdash;the "import" then select "import existing project" then click archive file, and then I click on next, and below error comes up: "Some projects cannot be imported because they already exist in the workspace"
asked Jan 22, 2020 jwilliam 3.9k points