Python Forum

Full Version: "'DataFrame' objects are mutable, thus they cannot be hashed"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
You reassigned "market = pd.read_csv..."
so absolutely it is not equal to df_name anymore, so cannot replace df_name with market