๐Ÿ€Zerve chosen as NCAA's Agentic Data Platform for 2026 Hackathonยท๐ŸงฎMeet the Zerve Team at Data Decoded Londonยท๐Ÿ“ˆWe're hiring โ€” awesome new roles just gone live!
Back
Pandas

TypeError: Unhashable Type: 'list' โ€” How to Fix It

Answer

This error means you're trying to use a list where Python expects a hashable type โ€” usually as a dictionary key, in a set, or in a pandas groupby/merge operation. Fix it by converting the list to a tuple, or by restructuring your data so columns don't contain lists.

Why This Happens

Python requires dictionary keys, set elements, and groupby columns to be hashable (immutable). Lists are mutable and therefore unhashable. This commonly happens when a dataframe column contains lists as values and you try to groupby, merge, or dedupe on that column.

Solution

The rule: if you need to group, merge, or dedupe on a column with lists, convert to tuples or strings first.

import pandas as pd

# โŒ Problematic: list as dictionary key
my_dict = {[1, 2]: 'value'}
# TypeError: unhashable type: 'list'

# โœ… Fixed: use tuple instead
my_dict = {(1, 2): 'value'}

# โŒ Problematic: groupby on column containing lists
df = pd.DataFrame({'tags': [['a', 'b'], ['a', 'c'], ['a', 'b']], 'value': [1, 2, 3]})
df.groupby('tags').sum()
# TypeError: unhashable type: 'list'

# โœ… Fixed: convert lists to tuples for groupby
df['tags_tuple'] = df['tags'].apply(tuple)
df.groupby('tags_tuple').sum()

# โœ… Alternative: convert lists to strings
df['tags_str'] = df['tags'].apply(lambda x: ','.join(x))
df.groupby('tags_str').sum()

Better Workflow

Zerve displays column dtypes inline, so you can spot columns containing lists or other complex types before they break downstream operations.

Better workflow

Related Topics

Decision-grade data work

Explore, analyze and deploy your first project in minutes