

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Multiple Conditions
incomplete
2: The Not Operator
incomplete
3: Filter Methods
incomplete
4: Binning
incomplete
5: String Operations
incomplete
6: Filtering With String Methods
incomplete
7: Sorting Data
incomplete
8: More Sorting
incomplete
9: Conditional Updates
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
"Binning" means grouping continuous numbers into discrete categories. Say you have some temperature readings, you could "bin" them into three categories: "Cold", "Normal", and "Hot":
Other examples include:
A, B, C, D, and F.3.2, 4.7...), you could use tiers (Low, Mid, Top).So, why bin your data?
The pd.cut() method is an easy way to create "bins" in a DataFrame.
Here we create a new rating_tier column set to "Low", "Mid", or "Top" based on the rating column:
# 0 up to 3 = Low
# above 3 up to 4 = Mid
# above 4 up to 5 = Top
df["rating_tier"] = pd.cut(
df["rating"],
bins=[0, 3, 4, 5],
labels=["Low", "Mid", "Top"],
include_lowest=True,
)
The include_lowest=True argument makes sure the very first edge (0) is included in the lowest bin.
SnackStack's support team wants a quick categorical view of the device fleet for their dashboard: a temperature zone and a battery tier for every device.
Complete the categorize_devices function. It accepts a DataFrame of devices and returns a copy with two new categorical columns.
Use float("-inf") and float("inf") when the values are unbounded