I have a dataset with dishes and scores, but when i try to make a bar-chart i get the same error message everytime.
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("https://gitlab.stud.iie.ntnu.no/nilstesd/python-big-data/raw/master/data/dishes.csv", sep=";", encoding="utf-8")
print(df.head())
df = df.groupby(['Dish']).mean()
df = df.mean(['Dish']).values
df = df.mean(['Score']).values
plt.figure(figsize = (8,6), dpi = 72)
plt.xlabel('Dish')
plt.ylabel('Score')
plt.title('Dishes')
ax = plt.gca()
colors= ['r', 'b']
df.plot(kind='bar',color=colors, alpha=0.75, ax=ax)
plt.grid(b=True, which='major', linewidth=1.0)
plt.grid(b=True, which='minor')
TypeError: unhashable type: 'list
CodePudding user response:
You don't need to reassign each column of the groupby object to itself: the lines df = df.mean(['Dish']).values
and df = df.mean(['Score']).values
should be removed as pointed out in the comments by @Henry Ecker and @azro
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("https://gitlab.stud.iie.ntnu.no/nilstesd/python-big-data/raw/master/data/dishes.csv", sep=";", encoding="utf-8")
print(df.head())
df = df.groupby(['Dish']).mean()
plt.figure(figsize = (8,6), dpi = 72)
plt.xlabel('Dish')
plt.ylabel('Score')
plt.title('Dishes')
ax = plt.gca()
colors= ['r', 'b']
df.plot(kind='bar',color=colors, alpha=0.75, ax=ax)
plt.grid(b=True, which='major', linewidth=1.0)
plt.grid(b=True, which='minor')
plt.show()