Skip to content
CampusEduX

Problem 2: Extract Features from a Date Column

Easypython
Learn the Concept: Feature Engineering

Problem 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

text
date 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 Feature
    Easy · python
    Solve Problem
  • Problem 3: Generate Polynomial Features
    Easy · python
    Solve Problem
  • Problem 4: Bin a Continuous Feature into Categories
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...