Comments (1)
The bug in the code berri_bikes.loc[:, 'weekday'] = berri_bikes.index.weekday is that the slice [:, 'weekday'] is unhashable.
A hashable type is a type that can be used as a key in a dictionary or a set. Slices are not hashable because they are not immutable. This means that they can be changed after they are created.
To fix the bug, you need to use a different way to slice the berri_bikes DataFrame. One way to do this is to use the iloc attribute. The iloc attribute allows you to slice a DataFrame by integer location.
The following code will fix the bug:
Python
berri_bikes.loc[:, 'weekday'] = berri_bikes.index.iloc[:, -1]
Use code with caution. Learn more
The -1 in the iloc slice tells Python to select the last column of the berri_bikes DataFrame.
Another way to fix the bug is to convert the berri_bikes.index.weekday series to a list before slicing it. The following code will also fix the bug:
Python
berri_bikes.loc[:, 'weekday'] = list(berri_bikes.index.weekday)
Use code with caution. Learn more
Which method you choose to use is a matter of personal preference. However, the iloc method is generally more efficient and easier to read.
Used bard btw for this
from pandas-cookbook.
Related Issues (20)
- ImportError: No module named notebook.notebookapp
- Update to Chapter 6
- Unspecified why used .loc()
- Chapter 1: first cell raises FutureWarning about mpl_style HOT 1
- Chapter 5 - the url template is outdated leading to 404: Not Found HOT 12
- Where is semicolon separated bikes.csv file? HOT 1
- Chapter 1: broken dataframe file is really broken HOT 2
- Chapter 7.3: pandas.DataFrame.sort()
- Dockerfile Out-of-Date
- Feature: Run Examples Online
- Prueba
- readme.md links
- Ch.3 link is out of date on your site
- Is there a known port for Python 3? HOT 2
- Chapter 4 TypeError:unhashable type:'slice' HOT 2
- Binder: Could not find a version that satisfies the requirement matplotlib==3.7.1
- Something is wrong here where Binder doesn't work HOT 1
- Broken link on the home page
- Issue with MyBinder Build: pip install command fails with non-zero exit code 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandas-cookbook.