Home > other >  TypeError: unhashable type: 'list' when creating a new definition
TypeError: unhashable type: 'list' when creating a new definition

Time:11-23

Im creating a definition to calculate mean,sem and count for paramater 1, paramater 2 and the value. Each .mean(), .sem(), .count(), .groupby() all come from pandas library.

def mean_SEM_Count(para1,para2,value):
    mean=df.groupby([para1],[para2])[value].mean()
    SEM=df.groupby([para1],[para2])[value].sem()
    COUNT=df.groupby([para1],[para2])[value].count()

So when i use this definition, i can call the values for each (para1,para2,value) from my dataframe(df) which comes from an excel sheet

Example:

df1 = mean_SEM_Count(para1 = 'Time', para2 = 'drug', value = 'food')

But i get the following error:

TypeError: unhashable type: 'list'

What am i doing wrong?

CodePudding user response:

There is necessary change:

df.groupby([para1],[para2])

to:

df.groupby([para1,para2])

Btw, here is possible use only GroupBy.agg:

out = df.groupby([para1,para2])[para3].agg(['mean','sem','count'])
  • Related