Question

This is for python. I am getting the error, "TypeError: 'Series' objects are mutable, thus they...

This is for python.

I am getting the error, "TypeError: 'Series' objects are mutable, thus they cannot be hashed". (avgOPSdict is a dictionary, year is a list). Any help would be appreciated! How would I go about fixing this code?

yearAvgOPS = []
for i in range (0, len(playerOPS)):
x = avgOPSdict[year[i]]
#this line is indented but chegg doesn't let me indent
yearAvgOPS.append(x) #this line is indented but chegg doesn't let me indent
print(yearAvgOPS)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Point-1: Let first learn about what are mutable and immutable objects. In python, if the value of a variable can be changed it is called mutable. While those objects which don't change their values are called immutable. Objects of built-in types like int, float,str and bool, etc. are immutable. Objects of built-in types like list, set, dict are mutable.

Poitnt-2: Another thing we must know about is hashable objects. An object is hashable or can be hashed if it's hash value is not changed during its lifetime. All of Python’s immutable built-in objects can be hashed or are hashable but lists or dictionaries are not hashable since they are mutable and their values can be changed.

Answer: So here in your code you are trying to add it to a dictionary to fix it use immutable objects (tuple, string, int.) as keys in your dictionary.

avgOPSdict[year[i]] is a mutable object so it cannot be hashed.

HAPPY LEARNING

Add a comment
Know the answer?
Add Answer to:
This is for python. I am getting the error, "TypeError: 'Series' objects are mutable, thus they...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am getting an error in R and am unsure how to correct it. I am getting an error from the r2 line, "Error in xc[1:(...

    I am getting an error in R and am unsure how to correct it. I am getting an error from the r2 line, "Error in xc[1:(n - 2)] : only 0's may be mixed with negative subscripts." tmpFn <- function(xVec) { xc <- xVec - mean(xVec) denom <- sum(xc^2) n <- length(x) r1 <- sum( xc[2:n] * xc[1:(n-1)] )/denom r2 <- sum( xc[3:n] * xc[1:(n-2)] )/denom list(r1 = r1, r2 = r2) } tmpFn(seq(2, 56, 3)) 10. (a) Given a...

  • I am using python3.6 and i am getting an error on line 42 num = int(fin.readline())...

    I am using python3.6 and i am getting an error on line 42 num = int(fin.readline()) #reading first value valueError: invalid literal, for int() with base 10 Any help is appreciated, here is the code. reads from txt file a few integers in an array and sorts them. thank you! # Function to do insertion sort def insertionSort(arr):     # Traverse through 1 to len(arr)     for i in range(1, len(arr)):         key = arr[i]         # Move elements of...

  • In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as...

    In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list of values (words from file of respective size) associated with those keys I am reading from a file of strings, where I am only interested with words of length 4, 5, and 6 to compute my program reading the text file line by line: At first, I have an empty dictionary then to that I...

  • What is wrong with my python code. I am receiving this error: Traceback (most recent call...

    What is wrong with my python code. I am receiving this error: Traceback (most recent call last): File "C:/Users/owner/Documents/numberfive.py", line 7, in if age > 18: TypeError: unorderable types: str() > int() My code is age= input("Enter your age:") if age > 18: print("You can vote.") else: print("You can't vote.") if age > 64: print ("You're a Senior Citizen...you deserve two votes") endofprogram = input("Please hit enter to exit from this program:")

  • Starting out with Python 4th edition I need help I followed a tutorial and have messed...

    Starting out with Python 4th edition I need help I followed a tutorial and have messed up also how does one include IOError and IndexError exception handling? I'm getting errors: Traceback (most recent call last): File, line 42, in <module> main() File , line 37, in main winning_times = years_won(user_winning_team_name, winning_teams_list) File , line 17, in years_won for winning_team_Index in range(len(list_of_teams)): TypeError: object of type '_io.TextIOWrapper' has no len() Write program champions.py to solve problem 7.10. Include IOError and IndexError...

  • I am doing this problem and I am getting the z value correctly, but I cannot...

    I am doing this problem and I am getting the z value correctly, but I cannot figure out the p value. I am using a calculator so I anyone can explain how to find the p value for me that would be great. Assume that z is the test statistic. (a) Ho: μ = 22.5, Ha: μ > 22.5; x = 26.4, σ = 7.1, n = 20 (i) Calculate the test statistic z. (Give your answer correct to two...

  • Hi I am using python and I keep getting this error with my code. Traceback (most...

    Hi I am using python and I keep getting this error with my code. Traceback (most recent call last): ['1'] Traceback (most recent call last): File "/Users/isabellawelch/Python ish/shuffle.py", line 86, in <module> emp = Employee(emp_data[0], emp_data[1], emp_data[2], emp_data[3], emp_data[4]) IndexError: list index out of range What does it mean and how do i fix it?? from tkinter import Tk, Label, Button, Entry, END employees = [] class Employee: def __init__(self, empno, name, addr, hwage, hworked): self.empno = empno self.name =...

  • I am suppose to have my array before the main class but I am getting the...

    I am suppose to have my array before the main class but I am getting the error 7 errors found: File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020 classes\How to program java (Late Objects)\PO1\Test_ResidencePolicy.java [line: 60] Error: non-static variable objectArray cannot be referenced from a static context File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020 classes\How to program java (Late Objects)\PO1\Test_ResidencePolicy.java [line: 61] Error: non-static variable objectArray cannot be referenced from a static context File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020 classes\How to program java (Late Objects)\PO1\Test_ResidencePolicy.java [line: 67] Error: non-static variable objectArray cannot...

  • Python You will download a file by right clicking on the file name then chose Save...

    Python You will download a file by right clicking on the file name then chose Save link As: WorldSeriesWinners.txt . This file contains a chronological list of the World Series winning teams from 1903 through 2009. (The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note that the World Series was not played in 1904 or 1994.) Write a...

  • I keep on getting the wrong answer. I am recording a 105,937.50 for the 2nd year....

    I keep on getting the wrong answer. I am recording a 105,937.50 for the 2nd year. the answer says $129,479. Would I be able to get a thorough step by step answer in order for me to see what I am doing wrong with the Double Declining Balance Method. Thank you. Beauty Company purchased a machine valued at $565,000 on September 1. The equipment has an estimated useful life of eight years or 5.5 million units. The equipment is estimated...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT