items = ['1', '2', '3']
for item in items:
df_list[item]= df.loc[file_df['Item'] == item]
This works fine. However if my item list is something else, for example:
items = [{'code': '1', 'other_needed_value': 1}, {'code': '2', 'other_needed_value': 2}, {'code': '3', 'other_needed_value': 3}]
for item in items:
code = item['code']
df_list[item]= df.loc[file_df['Item'] == code]
Obviously I'm comparing file_df['Item'] to a string, however I get this error from pandas
unhashable type: 'dict'
How should I solve this issue? Thanks in advance.
itemor is this a typo? Also it'd be good to put the full Traceback error so we can see which line is causing the problemitemas a dict key, whenitemis itself adict. If you meant to usecodeas the dict key, then that's just a typo. Otherwise please refer to the linked duplicate.df.loc[file_df['Item'] == code]to a temporary variable first, before assigning that todf_list[item]. You would have immediately seen that the problem was in the second part.