Data types

Contents

Data types#

pandas generally inherits its types system from NumPy. Below, we consider some features exclusive to pandas, and options for processing pandas series/data frames specific to particular data types.

Date & time#

Pandas provides an option for specifying a time zone for a datetime object.

The following table lists features of the Pandas design that allow you to work with datetime and timedelta objects.

Function / Method

Description

pd.to_datetime()

Convert strings, numbers, etc. to datetime64[ns]

pd.date_range()

Create a range of dates with fixed frequency

pd.bdate_range()

Like date_range but excludes weekends/holidays (business days)

pd.to_timedelta()

Convert strings or numbers to timedelta64[ns]

pd.timedelta_range()

Create a range of timedeltas

Series.dt

Accessor for datetime and timedelta components (e.g. .dt.year, .dt.days)

Series.dt.date

Extract just the date part (as datetime.date)

Series.dt.time

Extract just the time part (as datetime.time)

Series.dt.tz_localize()

Localize naive datetime to a timezone

Series.dt.tz_convert()

Convert timezone-aware datetimes to another timezone

Series.dt.normalize()

Set time to midnight (00:00:00)

Series.dt.floor(freq)

Round down to nearest frequency

Series.dt.ceil(freq)

Round up to nearest frequency

Series.dt.round(freq)

Round to nearest frequency

Series.dt.strftime(fmt)

Format datetime as string using strftime format

Series.dt.total_seconds()

Get total seconds from timedelta

Series.dt.days / dt.seconds

Extract days or seconds from timedelta

DataFrame.resample()

Resample time series data

DataFrame.asfreq(freq)

Change frequency without resampling

DataFrame.shift(periods, freq)

Shift data in time

DataFrame.diff()

Calculate timedelta difference between rows

DatetimeIndex, TimedeltaIndex

Specialized index types for time-aware indexing and slicing

DataFrame.set_index("timestamp")

Useful to enable datetime indexing/resampling

DataFrame.rolling(window="30D")

Rolling operations over time-based windows

Check details in: