pandas.Timestamp¶
-
class
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.
Parameters: ts_input : datetime-like, str, int, float
Value to be converted to Timestamp.
freq : str, DateOffset
Offset which Timestamp will have.
tz : str, pytz.timezone, dateutil.tz.tzfile or None
Time zone for time which Timestamp will have.
unit : str
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.
year, month, day : int
New in version 0.19.0.
hour, minute, second, microsecond : int, optional, default 0
New in version 0.19.0.
nanosecond : int, optional, default 0
New in version 0.23.0.
tzinfo : datetime.tzinfo, optional, default None
New in version 0.19.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.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
asm8Return numpy datetime64 format in nanoseconds. daydayofweekReturn day of the week. dayofyearReturn the day of the year. days_in_monthReturn the number of days in the month. daysinmonthReturn the number of days in the month. foldfreqfreqstrReturn the total number of days in the month. houris_leap_yearReturn True if year is a leap year. is_month_endReturn True if date is last day of month. is_month_startReturn True if date is first day of month. is_quarter_endReturn True if date is last day of the quarter. is_quarter_startReturn True if date is first day of the quarter. is_year_endReturn True if date is last day of the year. is_year_startReturn True if date is first day of the year. microsecondminutemonthnanosecondquarterReturn the quarter of the year. resolutionReturn resolution describing the smallest difference between two times that can be represented by Timestamp object_state secondtzAlias for tzinfo tzinfovalueweekReturn the week number of the year. weekday_name(DEPRECATED) .. deprecated:: 0.23.0 weekofyearReturn the week number of the year. yearMethods
astimezoneConvert tz-aware Timestamp to another time zone. ceilreturn a new Timestamp ceiled to this resolution combine(date, time)date, time -> datetime with same date and time fields ctimeReturn ctime() style string. dateReturn date object with same year, month and day. day_nameReturn the day name of the Timestamp with specified locale. dstReturn self.tzinfo.dst(self). floorreturn a new Timestamp floored to this resolution fromisocalendarint, int, int -> Construct a date from the ISO year, week number and weekday. fromisoformatstring -> datetime from datetime.isoformat() output fromordinal(ordinal[, freq, tz])passed an ordinal, translate and convert to a ts note: by definition there cannot be any tz info on the ordinal itself fromtimestamp(ts)timestamp[, tz] -> tz’s local time from POSIX timestamp. isocalendarReturn a 3-tuple containing ISO year, week number, and weekday. isoformatisoweekdayReturn the day of the week represented by the date. month_nameReturn the month name of the Timestamp with specified locale. normalizeNormalize Timestamp to midnight, preserving tz information. now([tz])Return new Timestamp object representing current time local to tz. replaceimplements datetime.replace, handles nanoseconds roundRound the Timestamp to the specified resolution strftimeformat -> strftime() style string. strptime(string, format)Function is not implemented. timeReturn time object with same time but with tzinfo=None. timestampReturn POSIX timestamp as float. timetupleReturn time tuple, compatible with time.localtime(). timetzReturn time object with same time and tzinfo. to_datetime64Return a numpy.datetime64 object with ‘ns’ precision. to_julian_dateConvert TimeStamp to a Julian Date. to_numpyConvert the Timestamp to a NumPy datetime64. to_periodReturn an period of which this timestamp is an observation. to_pydatetimeConvert a Timestamp object to a native Python datetime object. today(cls[, tz])Return the current time in the local timezone. toordinalReturn proleptic Gregorian ordinal. tz_convertConvert tz-aware Timestamp to another time zone. tz_localizeConvert naive Timestamp to local time zone, or remove timezone from tz-aware Timestamp. tznameReturn self.tzinfo.tzname(self). utcfromtimestamp(ts)Construct a naive UTC datetime from a POSIX timestamp. utcnow()Return a new Timestamp representing UTC day and time. utcoffsetReturn self.tzinfo.utcoffset(self). utctimetupleReturn UTC time tuple, compatible with time.localtime(). weekdayReturn the day of the week represented by the date.