jvns / pandas-cookbook

Recipes for using Python's pandas library
6.68k stars 2.32k forks source link

Chapter 4 TypeError:unhashable type:'slice' #77

Open chenlee1990 opened 3 years ago

chenlee1990 commented 3 years ago

when I write this line berri_bikes.loc[:, 'weekday'] = berri_bikes.index.weekday

If we run then we will see the bug: TypeError:unhashable type:'slice'

Anyone can tell me what happen and how to fix the bug?

chenlee1990 commented 3 years ago

the problem is sloved

jozefkip commented 3 years ago

What was the fix? I seem to run into the same problem.

edit: apparently when creating berri_bikes it is essential to use the double brackets: berri_bikes = bikes[['Berri 1']].copy()