liveBook · Manning

Timestamp

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

A timestamp object represents a specific date and time as a structured value supporting temporal calculations and comparisons.

A timestamp represents one specific point in calendar time: a birth, departure, meeting, or recorded event. Unlike a timedelta, which measures elapsed time, it can be described by year, month, day, hour, minute, and second. section 10.0

Use pandas timestamps to turn date information into workable analytical values:

  • Parse individual strings, Series, or CSV columns with `pd.to_datetime`; recognized formats can include dates, clock times, and month or day-first arrangements. section 10.0 section 10.2
  • Inspect components such as month, month name, hour, day of week, and leap-year status through the `dt` accessor. section 10.0
  • Subtract timestamps to produce timedeltas, then compare those durations with values such as `1 minute` or `10 hours`. section 10.0 section 10.2
  • Place timestamps in an index to retrieve exact dates, months, years, or date ranges, and resample observations into time periods. section 10.10 section 10.8

From taxi timestamps to trip durations

Parse `tpep_pickup_datetime` and `tpep_dropoff_datetime` while reading the CSV. Subtract pickup from dropoff to create `trip_time`, filter rides shorter than `1 minute`, and extend the analysis by grouping durations into short, medium, and long bins. section 10.2

filename = '../data/nyc_taxi_2019-07.csv'

df = (
    pd
    .read_csv(filename,
              usecols=['tpep_pickup_datetime',
                       'tpep_dropoff_datetime',
                       'trip_distance',
                       'passenger_count',
                       'total_amount'],
              parse_dates=['tpep_pickup_datetime',
                           'tpep_dropoff_datetime'])
)

Inspect the complete CSV-loading pattern that selects taxi fields and parses both timestamp columns during import. section 10.2

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Explains parsing, components, arithmetic, comparisons, indexed retrieval, slicing, and resampling through executable data tasks.
Examples
Uses formatted date strings, oil prices, New York taxi rides, and Apollo mission launch dates.
What it assumes
Uses Python and pandas data structures while distinguishing a timestamp from the timedelta representing elapsed time.
What you can do after
Apply it via pandas to parse dates, calculate durations, filter records, query periods, and resample time series.
How it connects
Connects timestamps with timedeltas, time series, datetime indexes, boolean filtering, and resampling.

Also explained in

Compare how 10 books explain timestamp →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.