Problem 2: Extract Features from a Date Column
Easypython
Learn the Concept: Feature EngineeringProblem Description
Write a Python program that extracts the day-of-week and an "is_weekend" flag from a date column in a DataFrame.
Input
A DataFrame with a date column.
Output
The DataFrame with new "dayofweek" and "is_weekend" columns.
Constraints
- Dates should be in a format Pandas can parse.
Example Input
text{"date": ["2024-01-06", "2024-01-08"]}
Example Output
textdate day_of_week is_weekend 0 2024-01-06 5 1 1 2024-01-08 0 0
Concepts Covered
pd.to_datetime(), .dt.dayofweek, .isin().
Related Problems
- Problem 1: Create an Interaction FeatureEasy · pythonSolve Problem
- Problem 3: Generate Polynomial FeaturesEasy · pythonSolve Problem
- Problem 4: Bin a Continuous Feature into CategoriesEasy · pythonSolve Problem