pandas.
Timestamp
Pandas replacement for python datetime.datetime object.
Timestamp is the pandas equivalent of python’s Datetime and is interchangeable with it in most cases. It’s the type used for the entries that make up a DatetimeIndex, and other timeseries oriented data structures in pandas.
Value to be converted to Timestamp.
Offset which Timestamp will have.
Time zone for time which Timestamp will have.
Unit used for conversion if ts_input is of type int or float. The valid values are ‘D’, ‘h’, ‘m’, ‘s’, ‘ms’, ‘us’, and ‘ns’. For example, ‘s’ means seconds and ‘ms’ means milliseconds.
Due to daylight saving time, one wall clock time can occur twice when shifting from summer to winter time; fold describes whether the datetime-like corresponds to the first (0) or the second time (1) the wall clock hits the ambiguous time
New in version 1.1.0.
Notes
There are essentially three calling conventions for the constructor. The primary form accepts four parameters. They can be passed by position or keyword.
The other two forms mimic the parameters from datetime.datetime. They can be passed by either position or keyword, but not both mixed together.
datetime.datetime
Examples
Using the primary calling convention:
This converts a datetime-like string
>>> pd.Timestamp('2017-01-01T12') Timestamp('2017-01-01 12:00:00')
This converts a float representing a Unix epoch in units of seconds
>>> pd.Timestamp(1513393355.5, unit='s') Timestamp('2017-12-16 03:02:35.500000')
This converts an int representing a Unix-epoch in units of seconds and for a particular timezone
>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific') Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')
Using the other two forms that mimic the API for datetime.datetime:
>>> pd.Timestamp(2017, 1, 1, 12) Timestamp('2017-01-01 12:00:00')
>>> pd.Timestamp(year=2017, month=1, day=1, hour=12) Timestamp('2017-01-01 12:00:00')
Attributes
asm8
Return numpy datetime64 format in nanoseconds.
day_of_week
Return day of the week.
day_of_year
Return the day of the year.
dayofweek
dayofyear
days_in_month
Return the number of days in the month.
daysinmonth
freqstr
Return the total number of days in the month.
is_leap_year
Return True if year is a leap year.
is_month_end
Return True if date is last day of month.
is_month_start
Return True if date is first day of month.
is_quarter_end
Return True if date is last day of the quarter.
is_quarter_start
Return True if date is first day of the quarter.
is_year_end
Return True if date is last day of the year.
is_year_start
Return True if date is first day of the year.
quarter
Return the quarter of the year.
tz
Alias for tzinfo.
week
Return the week number of the year.
weekofyear
day
fold
freq
hour
microsecond
minute
month
nanosecond
second
tzinfo
value
year
Methods
astimezone(tz)
astimezone
Convert tz-aware Timestamp to another time zone.
ceil(freq[, ambiguous, nonexistent])
ceil
Return a new Timestamp ceiled to this resolution.
combine(date, time)
combine
Combine date, time into datetime with same date and time fields.
ctime
Return ctime() style string.
date
Return date object with same year, month and day.
day_name
Return the day name of the Timestamp with specified locale.
dst
Return self.tzinfo.dst(self).
floor(freq[, ambiguous, nonexistent])
floor
Return a new Timestamp floored to this resolution.
fromisocalendar
int, int, int -> Construct a date from the ISO year, week number and weekday.
fromisoformat
string -> datetime from datetime.isoformat() output
fromordinal(ordinal[, freq, tz])
fromordinal
Passed an ordinal, translate and convert to a ts.
fromtimestamp(ts)
fromtimestamp
Transform timestamp[, tz] to tz’s local time from POSIX timestamp.
isocalendar
Return a 3-tuple containing ISO year, week number, and weekday.
isoformat
[sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
isoweekday
Return the day of the week represented by the date.
month_name
Return the month name of the Timestamp with specified locale.
normalize
Normalize Timestamp to midnight, preserving tz information.
now([tz])
now
Return new Timestamp object representing current time local to tz.
replace([year, month, day, hour, minute, …])
replace
Implements datetime.replace, handles nanoseconds.
round(freq[, ambiguous, nonexistent])
round
Round the Timestamp to the specified resolution.
strftime(format)
strftime
Return a string representing the given POSIX timestamp controlled by an explicit format string.
strptime(string, format)
strptime
Function is not implemented.
time
Return time object with same time but with tzinfo=None.
timestamp
Return POSIX timestamp as float.
timetuple
Return time tuple, compatible with time.localtime().
timetz
Return time object with same time and tzinfo.
to_datetime64
Return a numpy.datetime64 object with ‘ns’ precision.
to_julian_date()
to_julian_date
Convert TimeStamp to a Julian Date.
to_numpy
Convert the Timestamp to a NumPy datetime64.
to_period
Return an period of which this timestamp is an observation.
to_pydatetime
Convert a Timestamp object to a native Python datetime object.
today(cls[, tz])
today
Return the current time in the local timezone.
toordinal
Return proleptic Gregorian ordinal.
tz_convert(tz)
tz_convert
tz_localize(tz[, ambiguous, nonexistent])
tz_localize
Convert naive Timestamp to local time zone, or remove timezone from tz-aware Timestamp.
tzname
Return self.tzinfo.tzname(self).
utcfromtimestamp(ts)
utcfromtimestamp
Construct a naive UTC datetime from a POSIX timestamp.
utcnow()
utcnow
Return a new Timestamp representing UTC day and time.
utcoffset
Return self.tzinfo.utcoffset(self).
utctimetuple
Return UTC time tuple, compatible with time.localtime().
weekday