Panda Bear 2nd Birthday Girl 2 Year Old Birthday Pandas Bday Tank Top
FREE Shipping
Panda Bear 2nd Birthday Girl 2 Year Old Birthday Pandas Bday Tank Top
- Brand: Unbranded
Description
In [34]: dates = [ ....: pd . Timestamp ( "2012-05-01" ), ....: pd . Timestamp ( "2012-05-02" ), ....: pd . Timestamp ( "2012-05-03" ), ....: ] ....: In [35]: ts = pd . Series ( np . random . randn ( 3 ), dates ) In [36]: type ( ts . index ) Out[36]: pandas.core.indexes.datetimes.DatetimeIndex In [37]: ts . index Out[37]: DatetimeIndex(['2012-05-01', '2012-05-02', '2012-05-03'], dtype='datetime64[ns]', freq=None) In [38]: ts Out[38]: 2012-05-01 0.469112 2012-05-02 -0.282863 2012-05-03 -1.509059 dtype: float64 In [39]: periods = [ pd . Period ( "2012-01" ), pd . Period ( "2012-02" ), pd . Period ( "2012-03" )] In [40]: ts = pd . Series ( np . random . randn ( 3 ), periods ) In [41]: type ( ts . index ) Out[41]: pandas.core.indexes.period.PeriodIndex In [42]: ts . index Out[42]: PeriodIndex(['2012-01', '2012-02', '2012-03'], dtype='period[M]') In [43]: ts Out[43]: 2012-01 -1.135632 2012-02 1.212112 2012-03 -0.173215 Freq: M, dtype: float64 In [113]: dft2 = pd . DataFrame ( .....: np . random . randn ( 20 , 1 ), .....: columns = [ "A" ], .....: index = pd . MultiIndex . from_product ( .....: [ pd . date_range ( "20130101" , periods = 10 , freq = "12H" ), [ "a" , "b" ]] .....: ), .....: ) .....: In [114]: dft2 Out[114]: A 2013-01-01 00:00:00 a -0.298694 b 0.823553 2013-01-01 12:00:00 a 0.943285 b -1.479399 2013-01-02 00:00:00 a -1.643342 ... ... 2013-01-04 12:00:00 b 0.069036 2013-01-05 00:00:00 a 0.122297 b 1.422060 2013-01-05 12:00:00 a 0.370079 b 1.016331 [20 rows x 1 columns] In [115]: dft2 . loc [ "2013-01-05" ] Out[115]: A 2013-01-05 00:00:00 a 0.122297 b 1.422060 2013-01-05 12:00:00 a 0.370079 b 1.016331 In [116]: idx = pd . IndexSlice In [117]: dft2 = dft2 . swaplevel ( 0 , 1 ) . sort_index () In [118]: dft2 . loc [ idx [:, "2013-01-05" ], :] Out[118]: A a 2013-01-05 00:00:00 0.122297 2013-01-05 12:00:00 0.370079 b 2013-01-05 00:00:00 1.422060 2013-01-05 12:00:00 1.016331 The bins of the grouping are adjusted based on the beginning of the day of the time series starting point. This works well with frequencies that are multiples of a day (like 30D) or that divide a day evenly (like 90s or 1min). This can create inconsistencies with some frequencies that do not meet this criteria. To change this behavior you can specify a fixed Timestamp with the argument origin. In [330]: small = pd . Series ( .....: range ( 6 ), .....: index = pd . to_datetime ( .....: [ .....: "2017-01-01T00:00:00" , .....: "2017-01-01T00:30:00" , .....: "2017-01-01T00:31:00" , .....: "2017-01-01T01:00:00" , .....: "2017-01-01T03:00:00" , .....: "2017-01-01T03:05:00" , .....: ] .....: ), .....: ) .....: In [331]: resampled = small . resample ( "H" ) In [332]: for name , group in resampled : .....: print ( "Group: " , name ) .....: print ( "-" * 27 ) .....: print ( group , end = " \n\n " ) .....: Group: 2017-01-01 00:00:00 --------------------------- 2017 - 01 - 01 00 : 00 : 00 0 2017 - 01 - 01 00 : 30 : 00 1 2017 - 01 - 01 00 : 31 : 00 2 dtype: int64 If it helps, I had a similar need for exchange trading calendars. There was some excellent code buried in the Zipline project by Quantopian. I extracted out the relevant part and created a new project for creating market exchange trading calendars in pandas. The links are here, with some of the functionality described below.
will increment datetimes to the same time the next day whether a day represents 23, 24 or 25 hours due to daylight passing ` format ` if your strings have a consistent format ; - passing ` format = 'ISO8601' ` if your strings are all ISO8601 but not necessarily in exactly the same format ; - passing ` format = 'mixed' ` , and the format will be inferred for each element individually . You might want to use ` dayfirst ` alongside this .In [264]: pd . date_range ( .....: start = "7/1/2012" , end = "7/10/2012" , freq = pd . offsets . CDay ( calendar = cal ) .....: ) . to_pydatetime () .....: Out[264]: array([datetime.datetime(2012, 7, 2, 0, 0), datetime.datetime(2012, 7, 3, 0, 0), datetime.datetime(2012, 7, 5, 0, 0), datetime.datetime(2012, 7, 6, 0, 0), datetime.datetime(2012, 7, 9, 0, 0), datetime.datetime(2012, 7, 10, 0, 0)], dtype=object) In [265]: offset = pd . offsets . CustomBusinessDay ( calendar = cal ) In [266]: datetime . datetime ( 2012 , 5 , 25 ) + offset Out[266]: Timestamp('2012-05-29 00:00:00') In [267]: datetime . datetime ( 2012 , 7 , 3 ) + offset Out[267]: Timestamp('2012-07-05 00:00:00') In [268]: datetime . datetime ( 2012 , 7 , 3 ) + 2 * offset Out[268]: Timestamp('2012-07-06 00:00:00') In [269]: datetime . datetime ( 2012 , 7 , 6 ) + offset Out[269]: Timestamp('2012-07-09 00:00:00') In certain countries, such as the United States, there are laws ( Uniform Monday Holiday Act of 1968), whose rules are included in Pandas, print(USFederalHolidayCalendar.rules) as an example for developing other calendars. When I try to list the holidays in a date range, I get the following error: In[11]: tradingCal.holidays(datetime(2014, 12, 31), datetime(2016, 12, 31)) Here is what it can do by creating a pandas DatetimeIndex of all of the valid open hours for the NYSE: import pandas_market_calendars as mcal
Holiday: New Years Day (month=1, day=1, observance=
This particular day contains a day light savings time transition In [146]: ts = pd . Timestamp ( "2016-10-30 00:00:00" , tz = "Europe/Helsinki" ) # Respects absolute time In [147]: ts + pd . Timedelta ( days = 1 ) Out[147]: Timestamp('2016-10-30 23:00:00+0200', tz='Europe/Helsinki') # Respects calendar time In [148]: ts + pd . DateOffset ( days = 1 ) Out[148]: Timestamp('2016-10-31 00:00:00+0200', tz='Europe/Helsinki') In [149]: friday = pd . Timestamp ( "2018-01-05" ) In [150]: friday . day_name () Out[150]: 'Friday' # Add 2 business days (Friday --> Tuesday) In [151]: two_business_days = 2 * pd . offsets . BDay () In [152]: friday + two_business_days Out[152]: Timestamp('2018-01-09 00:00:00') In [153]: ( friday + two_business_days ) . day_name () Out[153]: 'Tuesday'The tradingCal instance seems to work in that I'm able to view the Holiday rules. In[10]: tradingCal.rules
- Fruugo ID: 258392218-563234582
- EAN: 764486781913
-
Sold by: Fruugo