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









