Run pandas Online

Work with Dates in pandas

pandas datetime values support efficient sorting, filtering, grouping, and calendar calculations.

What is Work with Dates in pandas?

pandas datetime values support efficient sorting, filtering, grouping, and calendar calculations.

Parse dates and calculate date-based values with pandas.

When should you use it?

  • Read, clean, and transform tabular data.
  • Analyze data from CSV, Excel, APIs, or databases.
  • Prepare reports, statistics, and chart data.

Example code

Run code →
main.py
import pandas as pd

events = pd.DataFrame({"date": ["2026-08-10", "2026-08-12"]})
events["date"] = pd.to_datetime(events["date"])
events["day"] = events["date"].dt.day_name()

print(events)

Expected output

date        day
0 2026-08-10     Monday
1 2026-08-12  Wednesday

How it works

To_datetime converts text to datetime values. The dt accessor exposes vectorized date components such as day names.

Change the values and run the program in the CodeUtility online Python compiler without installing Python locally.

Practice exercises

Modify the runnable example with the exercises below to build understanding beyond copying the result.

  1. Add rows, columns, and missing values.
  2. Combine filtering, sorting, and groupby into a small report.
  3. Load a real file, inspect dtypes, and handle invalid data.
Run in Python IDE →