Skip to content
Learn Netverks

Lesson

Step 17/36 47% through track

datetime-basics

Datetime basics

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Datetime basics: Pandas tabular manipulation—indexing, dtypes, reshaping, and analysis habits for real-world tables.

Timezone-aware datetime handling prevents off-by-one-day revenue and ops incidents.

You will apply Datetime basics in contexts like: Ops metrics, finance ledgers, and IoT sensor rollups.

Read the narrative, run `import pandas as pd` snippets with in-memory DataFrames (install pandas and numpy with pip if needed), inspect `.head()`, `.dtypes`, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

Parse dates with pd.to_datetime, extract components with .dt, and filter time ranges. Correct datetime dtypes unlock resampling and rolling windows later.

Parsing and dtype

import pandas as pd
dates = pd.to_datetime(['2024-01-15', '2024-02-01'])
print(dates.dtype)

.dt accessor

  • s.dt.year, .month, .day, .dayofweek
  • s.dt.strftime('%Y-%m') — format as string
  • s.dt.to_period('M') — monthly period

Filtering by date

df = pd.DataFrame({'date': pd.to_datetime(['2024-01-01','2024-06-01']),
                   'val': [1, 2]})
q1 = df[df['date'] < '2024-04-01']
print(q1)

Important interview questions and answers

  1. Q: Timezone aware?
    A: Use utc=True or tz_localize for global data—avoid ambiguous local times.
  2. Q: to_datetime errors?
    A: Use errors='coerce' for messy date strings like numeric conversion.

Self-check

  1. Parse a string column to datetime.
  2. Extract year and month with .dt.

Pitfall: Parse dates with pd.to_datetime before resample/rolling—object strings won't work.

Interview prep

to_datetime?

Parse strings to datetime64—foundation for resample/rolling.

.dt accessor?

Extract year, month, dayofweek from datetime Series.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • to_datetime errors?
  • Timezone aware?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump