Python Forum
"'DataFrame' objects are mutable, thus they cannot be hashed"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"'DataFrame' objects are mutable, thus they cannot be hashed"
#1
I've been having trouble in a few instances with what I think is the same core issue--I just can't identify exactly what it is.

markets = ['ES', 'GC', 'CL', 'EC', 'US']
margin_dict = {}
for market in markets:
    df_name = market
    market = pd.read_csv(r'C:\Users\Mark17\{}(daily).csv'.format(market), parse_dates=["Date"], index_col="Date")
    margin_dict[df_name] = market.iloc[:,0].max() * 0.15 * trade_unit[df_name] * multiplier[df_name]
This works. However, if I use "market" in place of "df_name" in the last line, then I get:
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed

Can someone please explain that?
Reply
#2
You reassigned "market = pd.read_csv..."
so absolutely it is not equal to df_name anymore, so cannot replace df_name with market
Mark17 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 426 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  mutable values to string items? fozz 15 2,701 Aug-30-2022, 07:20 PM
Last Post: deanhystad
  Mutable Strings millpond 3 2,500 Aug-24-2020, 08:42 AM
Last Post: millpond
  What is the meaning of mutable data type? qliu 3 2,876 Apr-17-2020, 07:20 PM
Last Post: deanhystad
  How to compare in python an input value with an hashed value in mysql table? Formationgrowthhacking 4 3,266 Jan-14-2020, 11:43 AM
Last Post: Formationgrowthhacking
  copying parts of mutable sequences Skaperen 1 2,189 Dec-02-2019, 10:34 AM
Last Post: Gribouillis
  A mutable string?? silentknight85 5 4,585 May-31-2019, 10:11 AM
Last Post: silentknight85
  compacting a mutable sequence Skaperen 6 4,343 Jan-23-2018, 03:54 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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