Block 26: Type Conversion & New Columns
Fix dtypes and engineer new features from existing columns.
Concepts
- astype() for type casting
- Creating new columns via arithmetic
- apply() with lambda for row/column transforms
- pd.to_datetime() for date handling
Code Examples
See exercise below.
Exercise
Add a BMI column to a health dataset using weight and height columns. Convert a 'date' string column to datetime and extract year, month, day.
Homework
Write an apply() function that categorizes a numeric column into 'low', 'medium', 'high' bins. Thursday