The "Change Data Type interview question" is a fundamental data engineering task involving schema modification. In real-world data pipelines, you often receive data in a format that doesn't match your analysis requirements (e.g., numbers stored as strings). Your goal is to transform a specific column in a dataset (usually a pandas DataFrame or a SQL table) to a different data type, such as converting an object/string column to an integer or float.
Google and other data-driven companies use the "Change Data Type coding problem" to verify a candidate's basic data manipulation skills. It ensures you know how to handle data cleaning and preparation, which often takes up 80% of a data scientist's or engineer's time. It also tests your awareness of potential data loss (e.g., converting float to int) and your ability to handle non-numeric values during conversion.
This problem follows the Data Transformation and Type Casting pattern.
.astype() in pandas or CAST() in SQL) to perform the conversion.Suppose you have a table of product prices where the price column is stored as strings: ["10.5", "20.0", "15"].
df['price'] = df['price'].astype(float).[10.5, 20.0, 15.0].
Now you can perform mathematical operations like sum() or mean().NaN values to an integer type without handling the nulls first, which often results in an error in many libraries.Master the data manipulation libraries specific to your role (e.g., pandas for Data Science, SQL for Backend/Data Engineering). Practice handling "dirty" data—columns that look like numbers but contain hidden spaces or special characters.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Calculate Compressed Mean | Easy | Solve | |
| Calculate Special Bonus | Easy | Solve | |
| Confusing Number | Easy | Solve | |
| Convert Date to Binary | Easy | Solve | |
| Count Asterisks | Easy | Solve |