

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: Data Cleaning
incomplete
2: Handling Missing Values
incomplete
3: Handling Duplicates
incomplete
4: Type Normalization
incomplete
5: Converting Types
incomplete
6: Cleaning Dates
incomplete
7: Working With Date Values
incomplete
8: Data Validation
incomplete
9: String Length
incomplete
10: Validation Summary
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
If you need to go from a number back to a string, use the .astype() method:
df["customer_id"] = df["customer_id"].astype(str)
This is especially useful when you have a column with mixed types: the astype() call will convert any individual number rows into strings.
Also, remember that sometimes conversion isn't straightforward and needs to start with some basic cleanup. For example, say we need to remove a % sign and then convert from a string to a number... we can use str.replace() before using pd.to_numeric():
df["discount"] = df["discount"].str.replace("%", "", regex=False)
df["discount"] = pd.to_numeric(df["discount"], errors="coerce")
SnackStack's accounting team has discount data in mixed percentage/decimal formats like "20.0%" and "0.15". The team needs to sort products by the biggest discounts but can't because of all the mixed types.
Complete the normalize_discounts function.