• Register
0 votes
3.4k views

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?

3.9k 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.

36.1k 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 2.9K views
2.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
0 votes
1 answer 1.7K views
1.7K views
Problem : I have a big dataframe and I am trying to split that and after concat that but facing following error first argument must be an iterable of pandas objects, you passed an object of type "dataframe"
asked Nov 14, 2019 peterlaw 6.9k points
1 vote
2 answers 219 views
219 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