In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to understand Pandas time series", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to understand Pandas time series.
Relying on NumPy's datetime64, timedelta64 and other data types, pandas can deal with all kinds of time series data, and can also call the time series functions of Python support libraries such as scikits.timeseries.
Pandas supports the following operations:
Parse time format string, np.datetime64, datetime.datetime and other time series data.
In [1]: import datetime
In [2]: dti = pd.to_datetime (['1max 1max 2018, np.datetime64 (' 2018-01-01')
: datetime.datetime (2018, 1, 1)])
...:
In [3]: dti
Out [3]: DatetimeIndex (['2018-01-01,' 2018-01-01, '2018-01-01]], dtype='datetime64 [ns]', freq=None)
Generate fixed-frequency date and time sequences such as DatetimeIndex, TimedeltaIndex, PeriodIndex, etc.
In [4]: dti = pd.date_range ('2018-01-01-01, periods=3, freq='H')
In [5]: dti
Out [5]:
DatetimeIndex (['2018-01-01-01-00,' 2018-01-01-01-01-01
'2018-01-01 02purl 0000']
Dtype='datetime64 [ns]', freq='H')
Process and convert date-time data with time zone.
In [6]: dti = dti.tz_localize ('UTC')
In [7]: dti
Out [7]:
DatetimeIndex (['2018-01-01-01 00,' 2018-01-01-01-01-01-01)
'2018-01-01 02purl 001R 000000']
Dtype='datetime64 [ns, UTC]', freq='H')
In [8]: dti.tz_convert ('US/Pacific')
Out [8]:
DatetimeIndex (['2017-12-31 16:00:00-08 DatetimeIndex,' 2017-12-31 17:00:00-08'
'2017-12-31 18:00:00-08 purl']
Dtype='datetime64 [ns, US/Pacific]', freq='H')
Resample at the specified frequency and convert it to a time series.
In [9]: idx = pd.date_range ('2018-01-01-01, periods=5, freq='H')
In [10]: ts = pd.Series (range (len (idx)), index=idx)
In [11]: ts
Out [11]:
2018-01-01 00:00:00 0
2018-01-01 01:00:00 1
2018-01-01 02:00:00 2
2018-01-01 03:00:00 3
2018-01-01 04:00:00 4
Freq: H, dtype: int64
In [12]: ts.resample ('2H'). Mean ()
Out [12]:
2018-01-01 00:00:00
2018-01-01 02:00:00 2.5
2018-01-01 04:00:00
Freq: 2H, dtype: float64
Calculate the date and time with an absolute or relative time difference.
In [13]: friday = pd.Timestamp ('2018-01-05')
In [14]: friday.day_name ()
Out [14]: 'Friday'
# add 1 calendar day
In [15]: saturday = friday + pd.Timedelta ('1day')
In [16]: saturday.day_name ()
Out [16]: 'Saturday'
# add 1 working day, skip from Friday to Monday
In [17]: monday = friday + pd.offsets.BDay ()
In [18]: monday.day_name ()
Out [18]: 'Monday'
Pandas provides a sleek and useful set of tools to do this.
Time series overview
Pandas supports four common time concepts:
Date time (Datetime): date time with a time zone, similar to the datetime.datetime of the standard library.
Time difference (Timedelta): absolute time period, similar to the datetime.timedelta of standard libraries.
Timespan: a time span defined at a specified frequency at a given point in time.
Date offset (Dateoffset): the period of time corresponding to a calendar operation, similar to dateutil's dateutil.relativedelta.relativedelta.
In general, the time series is mainly the time-type index of Series or DataFrame, which can be manipulated by time elements.
In [19]: pd.Series (range (3), index=pd.date_range ('2000 years, freq='D', periods=3))
Out [19]:
2000-01-01 0
2000-01-02 1
2000-01-03 2
Freq: D, dtype: int64
Of course, Series and DataFrame can also treat time series as data directly.
In [20]: pd.Series (pd.date_range ('2000 years, freq='D', periods=3))
Out [20]:
0 2000-01-01
1 2000-01-02
2 2000-01-03
Dtype: datetime64 [ns]
Series and DataFrame provide datetime, timedelta, Period extension types and proprietary usage, but Dateoffset is saved as object.
In [21]: pd.Series (pd.period_range ('1gamma, freq='M', periods=3))
Out [21]:
0 2011-01
1 2011-02
2 2011-03
Dtype: period [M]
In [22]: pd.Series ([pd.DateOffset (1), pd.DateOffset (2)])
Out [22]:
0
one
Dtype: object
In [23]: pd.Series (pd.date_range ('1gamma, freq='M', periods=3))
Out [23]:
0 2011-01-31
1 2011-02-28
2 2011-03-31
Dtype: datetime64 [ns]
Pandas uses NaT to represent date-time, time difference, and null values for time periods, representing values of missing or empty dates, similar to np.nan for floating-point numbers.
In [24]: pd.Timestamp (pd.NaT)
Out [24]: NaT
In [25]: pd.Timedelta (pd.NaT)
Out [25]: NaT
In [26]: pd.Period (pd.NaT)
Out [26]: NaT
# like np.nan, pd.NaT is not equal to pd.NaT
In [27]: pd.NaT = = pd.NaT
Out [27]: False
Time stamp vs. Time period
Timestamps are the most basic time series data, which are used to associate numerical values with time points. The Pandas object invokes point-in-time data through a timestamp.
In [28]: pd.Timestamp (datetime.datetime (2012, 5, 1))
Out [28]: Timestamp ('2012-05-01 0015-0000-0015')
In [29]: pd.Timestamp ('2012-05-01')
Out [29]: Timestamp ('2012-05-01 0015-0012)
In [30]: pd.Timestamp (2012, 5, 1)
Out [30]: Timestamp ('2012-05-01 0015-0012)
In most cases, however, it is more natural to change variables over a period of time. The time period represented by Period is more intuitive and can be inferred from a string in date-time format.
Examples are as follows:
In [31]: pd.Period ('2011-01')
Out [31]: Period ('2011-01,' M')
In [32]: pd.Period ('2012-05, freq='D')
Out [32]: Period ('2012-05-01,' D')
Timestamp and Period can be used as indexes. The Timestamp and Period lists as indexes are cast to the corresponding DatetimeIndex and PeriodIndex.
In [33]: dates = [pd.Timestamp ('2012-05-01')
....: pd.Timestamp ('2012-05-02')
....: pd.Timestamp ('2012-05-03')]
....:
In [34]: ts = pd.Series (np.random.randn (3) dates)
In [35]: type (ts.index)
Out [35]: pandas.core.indexes.datetimes.DatetimeIndex
In [36]: ts.index
Out [36]: DatetimeIndex (['2012-05-01,' 2012-05-02, '2012-05-03], dtype='datetime64 [ns]', freq=None)
In [37]: ts
Out [37]:
2012-05-01 0.469112
2012-05-02-0.282863
2012-05-03-1.509059
Dtype: float64
In [38]: periods = [pd.Period ('2012-01'), pd.Period ('2012-02'), pd.Period ('2012-03')]
In [39]: ts = pd.Series (np.random.randn (3) periods)
In [40]: type (ts.index)
Out [40]: pandas.core.indexes.period.PeriodIndex
In [41]: ts.index
Out [41]: PeriodIndex (['2012-01,' 2012-02, '2012-03], dtype='period [M]', freq='M')
In [42]: ts
Out [42]:
2012-01-1.135632
2012-02 1.212112
2012-03-0.173215
Freq: M, dtype: float64
Pandas can recognize these two expressions and transform them between them. Pandas backend uses Timestamp instances to represent timestamps and DatetimeIndex instances to represent timestamp sequences. Pandas uses Period object to represent scalar value of time period in accordance with the rule, and PeriodIndex to represent time period series. Future versions will support irregular time intervals with arbitrary start and end times.
Conversion timestamp
The to_datetime function is used to convert strings, epochs, and mixed date Series or date lists. When Series is converted, the Series with the same index is returned, and the date-time list is converted to DatetimeIndex:
In [43]: pd.to_datetime (['Jul 31, 2009,' 2010-01-10, None])
Out [43]:
0 2009-07-31
1 2010-01-10
2 NaT
Dtype: datetime64 [ns]
In [44]: pd.to_datetime (['2005-11-pound 23-pound,' 2010.12.31'])
Out [44]: DatetimeIndex (['2005-11-23,' 2010-12-31], dtype='datetime64 [ns]', freq=None)
To parse an European date (day-month-year), use the dayfirst keyword parameter:
In [45]: pd.to_datetime (['04-01-2012 10dayfirst=True], dayfirst=True)
Out [45]: DatetimeIndex (['2012-01-04 10 ns 00'], dtype='datetime64 [ns]', freq=None)
In [46]: pd.to_datetime (['14-01-2012,'01-14-2012], dayfirst=True)
Out [46]: DatetimeIndex (['2012-01-14,' 2012-01-14], dtype='datetime64 [ns]', freq=None)
Warning: as you can see from the above example, dayfirst is not that strict. If the first number cannot be parsed as a day, it will be parsed with dayfirst as False.
When to_datetime converts a single string, it returns a single Timestamp. Timestamp only supports string input, and does not support string parsing options such as dayfirst, format, and so on. If you want to use these options, use to_datetime.
In [47]: pd.to_datetime ('2010UniUniver 12')
Out [47]: Timestamp ('2010-11-12 00 00')
In [48]: pd.Timestamp ('2010UniUniver 12')
Out [48]: Timestamp ('2010-11-12 00 00')
Pandas also supports direct use of the DatetimeIndex builder:
In [49]: pd.DatetimeIndex (['2018-01-01-01,' 2018-01-03, '2018-01-05])
Out [49]: DatetimeIndex (['2018-01-03,' 2018-01-03, '2018-01-05], dtype='datetime64 [ns]', freq=None)
When you create a DatetimeIndex, pass the string infer to infer the frequency of the index.
In [50]: pd.DatetimeIndex (['2018-01-01-01,' 2018-01-03, '2018-01-05], freq='infer')
Out [50]: DatetimeIndex (['2018-01-03,' 2018-01-03, '2018-01-05], dtype='datetime64 [ns]', freq='2D')
Provide format parameters
To achieve precise conversion, in addition to passing the datetime string, you also specify the format parameter, which can also speed up the conversion.
In [51]: pd.to_datetime ('2010, 11, 12, format='%Y/%m/%d')
Out [51]: Timestamp ('2010-11-12 00 00')
In [52]: pd.to_datetime ('12-11-2010 00 format='%d-%m-%Y% M')
Out [52]: Timestamp ('2010-11-12 00 00')
To learn more about format options, see the Python date-time documentation.
Combine dates and times with multiple columns
Version 0.18.1 is new.
Pandas can also combine integers or string columns in DataFrame into Timestamp Series.
In [53]: df = pd.DataFrame ({'year': [2015, 2016]
....: 'month': [2,3]
....: 'day': [4,5]
....: 'hour': [2,3]})
....:
In [54]: pd.to_datetime (df)
Out [54]:
0 2015-02-04 02:00:00
1 2016-03-05 03:00:00
Dtype: datetime64 [ns]
It is also possible to pass only the columns required by the combination.
In [55]: pd.to_datetime (df [['year',' month', 'day']])
Out [55]:
0 2015-02-04
1 2016-03-05
Dtype: datetime64 [ns]
Pd.to_datetime looks for the standard name of the date-time component in the column name, including:
Required: year, month, day
Optional: hour, minute, second, millisecond, microsecond, nanosecond
Invalid data
When unresolvable, the default value of errors='raise' triggers an error:
In [2]: pd.to_datetime ([2009 asd' 07 asd'], errors='raise')
ValueError: Unknown string format
Errors='ignore' returns the original input:
In [56]: pd.to_datetime ([2009 asd' 07 asd'], errors='ignore')
Out [56]: Index ([2009 asd' 07 asd'], dtype='object')
Errors='coerce' converts unparsed data into NaT, that is, not Not a Time:
In [57]: pd.to_datetime ([2009 asd' 07 asd'], errors='coerce')
Out [57]: DatetimeIndex (['2009-07-31,' NaT'], dtype='datetime64 [ns]', freq=None)
Epoch timestamp
Pandas supports converting integer or floating point epoch time to Timestamp and DatetimeIndex. Given the way Timestamp objects are stored internally, the default unit for this conversion is nanosecond. However, it is common to use the specified other time unit unit to store the era data, which is calculated from the time point specified by the origin parameter.
In [58]: pd.to_datetime ([1349720105, 1349806505, 1349892905)
...: 1349979305, 1350065705], unit='s')
....:
Out [58]:
DatetimeIndex (['2012-10-08 18-15-15-05,' 2012-10-09-18-15-15-05')
'2012-10-10 18-18-15-15-50,' 2012-10-11-18-15-15-15
'2012-10-12 18-15-15-05']
Dtype='datetime64 [ns]', freq=None)
In [59]: pd.to_datetime ([1349720105100,1349720105200,1349720105300
...: 1349720105400, 1349720105500], unit='ms')
....:
Out [59]:
DatetimeIndex (['2012-10-08 18 15VR 05.100000mm,' 2012-10-08 18VR 1515 05.200000'
'2012-10-08 18 15 05.300000mm,' 2012-10-08 18 14 race 1515 V 05.400000'
'2012-10-08 18 purl 15 purl 05.500000']
Dtype='datetime64 [ns]', freq=None)
When you create an Timestamp or DatetimeIndex with an era timestamp with a tz parameter, you first convert the era timestamp to UTC, and then the result to the specified time zone. However, this mode of operation is now obsolete. For the epoch timestamps in other time zones Wall Time, it is recommended to convert the epoch timestamps to no time zone timestamps before localizing the time zone.
In [60]: pd.Timestamp (12623472000000000). Tz_localize ('US/Pacific')
Out [60]: Timestamp ('2010-01-01 12:00:00-0800 miles, tz='US/Pacific')
In [61]: pd.DatetimeIndex ([12623472000000000]) .tz_localize ('US/Pacific')
Out [61]: DatetimeIndex (['2010-01-01 12:00:00-08 dtype='datetime64], dtype='datetime64 [ns, US/Pacific]', freq=None)
Note: the Epoch time is rounded to the nearest nanosecond.
Warning: Python floating-point numbers are only accurate to 15 decimal places, so converting floating-point time can lead to inaccurate or runaway results. In the process of conversion, high-precision Timestamp will inevitably be rounded, and extremely accurate results can only be achieved by using fixed width types such as int64.
In [62]: pd.to_datetime ([1490195805.433, 1490195805.433502912], unit='s')
Out [62]: DatetimeIndex (['2017-03-22 15 dtype='datetime64 16VR 45.43300000088mm,' 2017-03-22 > 1515 dtype='datetime64 [ns]', freq=None)
In [63]: pd.to_datetime (1490195805433502912, unit='ns')
Out [63]: Timestamp ('2017-03-22 15purl 16purl 45.433502912')
See: apply origin parameters
Convert a timestamp into an era
Reverse the above to convert Timestamp to the unix era:
In [64]: stamps = pd.date_range ('2012-10-08 18 pd.date_range 15 periods=4 05mm, periods=4, freq='D')
In [65]: stamps
Out [65]:
DatetimeIndex (['2012-10-08 18-15-15-05,' 2012-10-09-18-15-15-05')
'2012-10-10 18-18-15-15-50,' 2012-10-11-18-15-15-05']
Dtype='datetime64 [ns]', freq='D')
First subtracts from the beginning of the era (midnight, January 1, 1970, UTC), and then divides by 1 second as the unit of time (unit='1s').
In [66]: (stamps-pd.Timestamp ("1970-01-01")) / / pd.Timedelta ('1s')
Out [66]: Int64Index ([1349720105, 1349806505, 1349892905, 1349979305], dtype='int64')
Apply the parameter `room`
Version 0.20.0 is new.
The origin parameter can specify an alternate start time for DatetimeIndex. For example, use 1960-01-01 as the start date:
In [67]: pd.to_datetime ([1,2,3], unit='D', origin=pd.Timestamp ('1960-01-01'))
Out [67]: DatetimeIndex (['1960-01-02,' 1960-01-03, '1960-01-04], dtype='datetime64 [ns]', freq=None)
The default value is origin='unix', which is 1970-01-01 00:00:00, which is generally referred to as the unix era or POSIX time.
In [68]: pd.to_datetime ([1,2,3], unit='D')
Out [68]: DatetimeIndex (['1970-01-02,' 1970-01-03, '1970-01-04], dtype='datetime64 [ns]', freq=None)
Generate timestamp range
The DatetimeIndex and Index builders can generate timestamp indexes, and here a list of datetime objects is provided.
In [69]: dates = [datetime.datetime (2012, 5, 1)
....: datetime.datetime (2012, 5, 2)
....: datetime.datetime (2012, 5, 3)]
....:
# pay attention to frequency information
In [70]: index = pd.DatetimeIndex (dates)
In [71]: index
Out [71]: DatetimeIndex (['2012-05-01,' 2012-05-02, '2012-05-03], dtype='datetime64 [ns]', freq=None)
# automatically convert to DatetimeIndex
In [72]: index = pd.Index (dates)
In [73]: index
Out [73]: DatetimeIndex (['2012-05-01,' 2012-05-02, '2012-05-03], dtype='datetime64 [ns]', freq=None)
In practical work, it is often necessary to generate ultra-long indexes with a large number of timestamps, and the input timestamps are boring and inefficient. If the timestamp is fixed frequency, the DatetimeIndex can be created with the date_range () and bdate_range () functions. The default frequency for date_range is calendar days, and the default frequency for bdate_range is working days:
In [74]: start = datetime.datetime (2011, 1,1)
In [75]: end = datetime.datetime (2012, 1,1)
In [76]: index = pd.date_range (start, end)
In [77]: index
Out [77]:
DatetimeIndex (['2011-01-01-01,' 2011-01-02, '2011-01-03,' 2011-01-04'
'2011-01-05,' 2011-01-06, '2011-01-07, 2011-01-08'
'2011-01-09,' 2011-01-10'
...
'2011-12-23,' 2011-12-24, '2011-12-25, 2011-12-26'
'2011-12-27, '2011-12-28,' 2011-12-29, '2011-12-30'
'2011-12-31,' 2012-01-01']
Dtype='datetime64 [ns]', length=366, freq='D')
In [78]: index = pd.bdate_range (start, end)
In [79]: index
Out [79]:
DatetimeIndex (['2011-01-03,' 2011-01-04, '2011-01-05,' 2011-01-06'
'2011-01-07,' 2011-01-10, '2011-01-11, 2011-01-12'
'2011-01-13,' 2011-01-14'
...
'2011-12-19,' 2011-12-20, '2011-12-21, 2011-12-22'
'2011-12-23,' 2011-12-26, '2011-12-27, 2011-12-28'
'2011-12-29,' 2011-12-30]
Dtype='datetime64 [ns]', length=260, freq='B')
Convenient functions such as date_range and bdate_range can call various frequency aliases:
In [80]: pd.date_range (start, periods=1000, freq='M')
Out [80]:
DatetimeIndex ['2011-01-31,' 2011-02-28, '2011-03-31,' 2011-04-30'
'2011-05-31,' 2011-06-30, '2011-07-31, 2011-08-31'
'2011-09-30,' 2011-10-31'
...
'2093-07-31,' 2093-08-31, '2093-09-30, 2093-10-31'
'2093-11-30,' 2093-12-31, 2094-01-31, 2094-02-28
'2094-03-31,' 2094-04-30]
Dtype='datetime64 [ns]', length=1000, freq='M')
In [81]: pd.bdate_range (start, periods=250, freq='BQS')
Out [81]:
DatetimeIndex ['2011-01-03,' 2011-04-01, '2011-07-01,' 2011-10-03'
'2012-01-02,' 2012-04-02, '2012-07-02, 2012-10-01'
'2013-01-01-01,' 2013-04-01'
...
'2071-01-01,' 2071-04-01, '2071-07-01, 2071-10-01'
'2072-01-01,' 2072-04-01, 2072-07-01, '2072-10-03'
'2073-01-02,' 2073-04-03]
Dtype='datetime64 [ns]', length=250, freq='BQS-JAN')
Date_range and bdate_range simplify the task of generating a date range by specifying parameters such as start, end, period, and freq. Start and end dates are required, so dates outside the specified range are not generated.
In [82]: pd.date_range (start, end, freq='BM')
Out [82]:
DatetimeIndex ('2011-01-31,' 2011-02-28, '2011-03-31,' 2011-04-29'
'2011-05-31,' 2011-06-30, '2011-07-29, 2011-08-31'
'2011-09-30,' 2011-10-31, '2011-11-30,' 2011-12-30]
Dtype='datetime64 [ns]', freq='BM')
In [83]: pd.date_range (start, end, freq='W')
Out [83]:
DatetimeIndex (['2011-01-02,' 2011-01-09, '2011-01-16,' 2011-01-23'
'2011-01-30,' 2011-02-06, '2011-02-13, 2011-02-20'
'2011-02-27,' 2011-03-06, '2011-03-13, 2011-03-20'
'2011-03-27,' 2011-04-03, '2011-04-10, 2011-04-17'
'2011-04-24,' 2011-05-01, '2011-05-08,' 2011-05-15
'2011-05-22,' 2011-05-29, '2011-06-05, 2011-06-12'
'2011-06-19,' 2011-06-26, '2011-07-03,' 2011-07-10
'2011-07-17,' 2011-07-24, 2011-07-31, 2011-08-07
'2011-08-14,' 2011-08-21, 2011-08-28, '2011-09-04'
'2011-09-11,' 2011-09-18, 2011-09-25, 2011-10-02
'2011-10-09,' 2011-10-16, '2011-10-23, 2011-10-30'
'2011-11-06,' 2011-11-13, 2011-11-20, 2011-11-27
'2011-12-04,' 2011-12-11, '2011-12-18, 2011-12-25'
'2012-01-01']
Dtype='datetime64 [ns]', freq='W-SUN')
In [84]: pd.bdate_range (end=end, periods=20)
Out [84]:
DatetimeIndex (['2011-12-05,' 2011-12-06, '2011-12-07,' 2011-12-08'
'2011-12-09,' 2011-12-12, 2011-12-13, 2011-12-14
'2011-12-15,' 2011-12-16, 2011-12-19, 2011-12-20
2011-12-21, 2011-12-22, 2011-12-23, 2011-12-26
'2011-12-27,' 2011-12-28, '2011-12-29,' 2011-12-30]
Dtype='datetime64 [ns]', freq='B')
In [85]: pd.bdate_range (start=start, periods=20)
Out [85]:
DatetimeIndex (['2011-01-03,' 2011-01-04, '2011-01-05,' 2011-01-06'
'2011-01-07,' 2011-01-10, '2011-01-11, 2011-01-12'
'2011-01-13,' 2011-01-14, '2011-01-17, 2011-01-18'
2011-01-19, 2011-01-20, 2011-01-21, 2011-01-24
'2011-01-25,' 2011-01-26, '2011-01-27,' 2011-01-28']
Dtype='datetime64 [ns]', freq='B')
Version 0.23.0 is new.
Specify start, end, periods to generate an equidistant date range from start to the end of end, which contains start and end, and the number of elements in the generated DatetimeIndex is the value of periods.
In [86]: pd.date_range ('2018-01-01-01,' 2018-01-05, periods=5)
Out [86]:
DatetimeIndex (['2018-01-01-01,' 2018-01-02, '2018-01-03,' 2018-01-04'
'2018-01-05']
Dtype='datetime64 [ns]', freq=None)
In [87]: pd.date_range ('2018-01-01-01,' 2018-01-05, periods=10)
Out [87]:
DatetimeIndex ('2018-01-01 00 00,' 2018-01-01 10 14) 40
'2018-01-01 21-20-00,' 2018-01-02-08-01-02
'2018-01-02 18-40-40-00-00,' 2018-01-03-05-20-00'
'2018-01-03 16-00-00-00,' 2018-01-04-04-02-40
'2018-01-04 13-20-00-00,' 2018-01-05-00-00-00-00-00]
Dtype='datetime64 [ns]', freq=None)
Custom frequency range
By setting the weekmask and holidays parameters, bdate_range can also generate a custom frequency date range. These parameters are only used to pass custom strings.
In [88]: weekmask = 'Mon Wed Fri'
In [89]: holidays = [datetime.datetime (2011, 1,5), datetime.datetime (2011, 3,14)]
In [90]: pd.bdate_range (start, end, freq='C', weekmask=weekmask, holidays=holidays)
Out [90]:
DatetimeIndex (['2011-01-03,' 2011-01-07, '2011-01-10,' 2011-01-12'
'2011-01-14,' 2011-01-17, '2011-01-19, 2011-01-21'
'2011-01-24, 2011-01-26'
...
'2011-12-09,' 2011-12-12, 2011-12-14, 2011-12-16
'2011-12-19,' 2011-12-21, 2011-12-23, 2011-12-26
'2011-12-28,' 2011-12-30]
Dtype='datetime64 [ns]', length=154, freq='C')
In [91]: pd.bdate_range (start, end, freq='CBMS', weekmask=weekmask)
Out [91]:
DatetimeIndex (['2011-01-03,' 2011-02-02, '2011-03-02, 2011-04-01'
'2011-05-02,' 2011-06-01, '2011-07-01, 2011-08-01'
'2011-09-02,' 2011-10-03, '2011-11-02,' 2011-12-02']
Dtype='datetime64 [ns]', freq='CBMS')
The limit of a timestamp
The lowest unit of Pandas timestamp is nanosecond, and the time span of 64-bit integer display is about 584 years. This is the limit of Timestamp:
In [92]: pd.Timestamp.min
Out [92]: Timestamp ('1677-09-21 00 12 43.145225')
In [93]: pd.Timestamp.max
Out [93]: Timestamp ('2262-04-11 23Pandas 4715) here, I believe you have a deeper understanding of "how to understand Pandas time series". You might as well do it! here is the website, more related content can go to the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.