综合单价分析2,85x1oo个返5个怎么计算的

to add this item to your wishlist, follow it, or mark it as not interested
Languages:
Full Audio
Simplified Chinese
Portuguese
Portuguese-Brazil
Includes 36 Steam Achievements
Title: Euro Truck Simulator 2
Developer:
Publisher:
Release Date: 16 Jan, 2013
Buy Euro Truck Simulator 2
Packages that include this game
Buy Euro Truck Simulator 2 - East Expansion Bundle
Includes 7 items:
Euro Truck Simulator 2, Euro Truck Simulator 2 - Czech Paint Jobs Pack, Euro Truck Simulator 2 - Fantasy Paint Jobs Pack, Euro Truck Simulator 2 - Force of Nature Paint Jobs Pack, Euro Truck Simulator 2 - Going East!, Euro Truck Simulator 2 - Ice Cold Paint Jobs Pack, Euro Truck Simulator 2 - Polish Paint Jobs Pack
Buy Euro Truck Simulator 2 - North Expansion Bundle
Includes 9 items:
Euro Truck Simulator 2, Euro Truck Simulator 2 - Danish Paint Jobs Pack, Euro Truck Simulator 2 - Fantasy Paint Jobs Pack, Euro Truck Simulator 2 - High Power Cargo Pack, Euro Truck Simulator 2 - Ice Cold Paint Jobs Pack, Euro Truck Simulator 2 - Norwegian Paint Jobs Pack, Euro Truck Simulator 2 - Scandinavia, Euro Truck Simulator 2 - Swedish Paint Jobs Pack, Euro Truck Simulator 2 - Viking Legends
Buy Euro Truck Simulator 2 - Deluxe Bundle
Includes 27 items:
Bus Driver, Euro Truck Simulator, Euro Truck Simulator 2, Euro Truck Simulator 2 - Brazilian Paint Jobs Pack, Euro Truck Simulator 2 - Canadian Paint Jobs Pack, Euro Truck Simulator 2 - Czech Paint Jobs Pack, Euro Truck Simulator 2 - Danish Paint Jobs Pack, Euro Truck Simulator 2 - Fantasy Paint Jobs Pack, Euro Truck Simulator 2 - Force of Nature Paint Jobs Pack, Euro Truck Simulator 2 - French Paint Jobs Pack, Euro Truck Simulator 2 - German Paint Jobs Pack, Euro Truck Simulator 2 - Going East!, Euro Truck Simulator 2 - High Power Cargo Pack, Euro Truck Simulator 2 - Ice Cold Paint Jobs Pack, Euro Truck Simulator 2 - Irish Paint Jobs Pack, Euro Truck Simulator 2 - Japanese Paint Jobs Pack, Euro Truck Simulator 2 - Norwegian Paint Jobs Pack, Euro Truck Simulator 2 - Polish Paint Jobs Pack, Euro Truck Simulator 2 - Russian Paint Jobs Pack, Euro Truck Simulator 2 - Scandinavia, Euro Truck Simulator 2 - Scottish Paint Jobs Pack, Euro Truck Simulator 2 - Swedish Paint Jobs Pack, Euro Truck Simulator 2 - UK Paint Jobs Pack, Euro Truck Simulator 2 - USA Paint Jobs Pack, Euro Truck Simulator 2 - Viking Legends, Scania Truck Driving Simulator, Trucks & Trailers
Downloadable Content For This Game
Buy Euro Truck Simulator 2 - Trucking Fan DLC Bundle
Requires the base game
on Steam in order to play.
Buy Euro Truck Simulator 2 - East + North Expansions
Includes 7 items:
Euro Truck Simulator 2 - Czech Paint Jobs Pack, Euro Truck Simulator 2 - Danish Paint Jobs Pack, Euro Truck Simulator 2 - Going East!, Euro Truck Simulator 2 - Norwegian Paint Jobs Pack, Euro Truck Simulator 2 - Polish Paint Jobs Pack, Euro Truck Simulator 2 - Scandinavia, Euro Truck Simulator 2 - Swedish Paint Jobs Pack
Recent updates
We are working hard to secure more truck licenses for our games, and we hope to be able to confirm some good news on this topic soon. Our fan community is fantastic - we are receiving great leads and active help in this area quite often, and your voice as heard on social media channels also means a lot. But the legal part of the licensing process can sometimes be very lengthy as you must have noticed by now, and we appreciate your patience.
Meanwhile though, we have revisited an existing truck model in ETS2 - the DAF XF 105. You may notice the similarity of this 3D model to the DAF XF mod by 50keda. That's no coincidence - 50keda is one of our great picks from the modding community to enter the professional game dev world as an SCS Software employee. The revision of the DAF XF 105, available soon in ETS2 update 1.25, is not just a simple merging of the mod that's already available to you, but is even further improvement with additional textures rework and remodeling of quite some parts - which we believe will be really appreciated by all DAF fans. Here is what you can look forward to...
With the Vive La France DLC for ETS2 we are trying to raise the bar on quality and realism once again.
As you may have noticed, with the Going East and Scandinavia DLC we were step by step increasing the quality of towns and cities. Going East gave you your first chance to drive through small towns - even though there were no delivery options there.
With the Scandinavia DLC we made an essential step forward by offering a new level of complexity and diversity in cities.
But these two DLCs are definitely not our last word in the matter!
Case in point, it is our pleasure to introduce you to La Rochelle - one of new cities which provide the chance to taste the natural beauty and variety of French cities and countryside. You will no longer be restricted to entering industrial zones via arterial roads but instead the cargo depots here are fully integrated into living city.
With the new DLC you can explore the medley of times and styles French cities have come to be revered for. Enjoy ancient architecture and narrow, winding roads back to back with fully modernized complexes and detached houses. Vive la France!
“Unexpectedly engrossing. Heed the mockers and you'll miss one of the PC's finest and freshest driving games.”
85/100 –
“With its stellar gameplay and presentation, Euro Truck Simulator 2 set a new standard for the simulation genre.”
95/100 –
“There are titles in the simulation market which can be sold on the novelty factor alone, but tend to be disappointing games. Euro Truck Simulator 2 is not one of them, it is strangely cathartic, engaging and relaxing.”
Just Updated
American Truck Simulator released
Our new game
has been released.
Start your new truck empire in the United States!
About This Game
Travel across Europe as king of the road, a trucker who delivers important cargo across impressive distances! With dozens of cities to explore from the UK, Belgium, Germany, Italy, the Netherlands, Poland, and many more, your endurance, skill and speed will all be pushed to their limits. If you’ve got what it takes to be part of an elite trucking force, get behind the wheel and prove it!
Transport a vast variety of cargo across more than 60 European cities.
Run your own business which continues to grow even as you complete your freight deliveries.
Build your own fleet of trucks, buy garages, hire drivers, manage your company for maximum profits.
A varied amount of truck tuning that range from performance to cosmetic changes.
Customize your vehicles with optional lights, bars, horns, beacons, smoke exhausts, and more.
Thousands of miles of real road networks with hundreds of famous landmarks and structures.
Take advantage of additional features of Euro Truck Simulator 2 by joining our online community on , our center for virtual truckers all around the world interested in Euro Truck Simulator 2 and future SCS Software's truck simulators.
Use in-game Photo Mode to capture the best moments and share them with thousands of people who love trucks.
Favorite the images you like the most and return to them anytime in the future.
Discuss the screenshots with everyone using World of Trucks.
See the best images hand-picked by the game creators in Editor's Pick updated almost every day. Try to get your own screenshot on this list!
Upload and use your custom avatar and license plate in the game.
More features coming soon!
To join , simply sign up with your Steam account .
World of Trucks is an optional service, registration on World of Trucks isn't required to play the game.
System Requirements
SteamOS + Linux
OS: Windows 7
Processor: Dual core CPU 2.4 GHz
Memory: 4 GB RAM
Graphics: GeForce GTS 450-class (Intel HD 4000)
Hard Drive: 3 GB available space
Recommended:
OS: Windows 7/8.1/10 64-bit
Processor: Quad core CPU 3.0 GHz
Memory: 6 GB RAM
Graphics: GeForce GTX 760-class (2 GB)
Hard Drive: 3 GB available space
OS: Mac OS X 10.9 (Mavericks)
Processor: Dual core CPU 2.4 GHz
Memory: 4 GB RAM
Graphics: GeForce GTS 450-class (Intel HD 4000)
Hard Drive: 3 GB available space
Recommended:
OS: Mac OS X 10.10 (Yosemite)
Processor: Quad core CPU 3.0 GHz
Memory: 6 GB RAM
Graphics: GeForce GTX 760-class (Intel HD 5300)
Hard Drive: 3 GB available space
OS: Linux Ubuntu 12.04
Processor: Dual core CPU 2.4 GHz
Memory: 4 GB RAM
Graphics: GeForce GTS 450-class (Intel HD 4000)
Hard Drive: 3 GB available space
Additional Notes: recent binary ATI or NVidia drivers (MESA may not work reliably)
Recommended:
OS: Linux Ubuntu 12.04
Processor: Quad core CPU 3.0 GHz
Memory: 6 GB RAM
Graphics: GeForce GTX 760-class (2 GB)
Hard Drive: 3 GB available space
Additional Notes: recent binary ATI or NVidia drivers (MESA may not work reliably)
(C) 2012 SCS Software. All brand names, trademarks, registered marks, logos, and symbols on vehicles in the game are property of their rightful owners. Used with kind permission.
More like this
Loading reviews...
Loading reviews...
Loading reviews...
Loading reviews...
Loading reviews...
Overwhelmingly Positive
(2,225 reviews)
Overwhelmingly Positive
(66,521 reviews)
quite a decent game I recommend playying taylor swift whilst you play.
well my first impressions were very good. I have currently put 91hours into the game and i play it a few times a week. But after i got to about 89 hours i started to exprience gltiches like the world disapreing. now this happenns alot. so i have stop playing for the time being. It would be nice if someone would know whats is going on!
Nice game!
Buy it on sale for a hoot. Briefly interesting but you will need a wheel. Joy stick too sensitive even on the dullest settings. Thumbs up if on sale and you get the sensitivity OK.
This game is awesome =]]
T) 10/10 xD
i love the game but scs should have included the dlc in the price of the game
You basically experience the game within the first 2 hours so if u like i then keep it, and if you dont return it nothing lose nothing gain I RECOMMEND
Product received for free
Product received for free
Nice game i love it
50 people found this review funny
Never been in Norway, so i decide to take a little delivery from Odense to the 1st city in Norway. In Denmark everything as planned, then i have to take the ferry and be more or less at 50 km from the arrival. I take the wrong ferry and find myself in Stavanger, 445km from the destination. Panic. I need 5.10 h to arrive, with 4.30 left.
It's 2 am. I Run at 140 kmh among the fiords like crazy, staying in the middle of the street to be faster. I arrive in the destination city cutting the last roundabout, 3 minutes before expiration. And they say this is a relaxing game! :steamhappy:
Was this review helpful?
9 people found this review funny
Remember driving around on GTA listening to the radio? Felt pretty awesome, right?Well, this is it.
Was this review helpful?
10/10 would be a truck driver in real life
Was this review helpful?
1 person found this review funny
Product received for free
Single player is amazing, Before i got this game on steam i played the disk version for around 500 to 600 hours and i still play it to this day. The game looks amazing and runs like a dream. The gameplay makes sence unlike other simulators and it can be very realistic at points. I recommend that you download the Multiplayer version though, It makes it a little more crazy with people doing stupid driving and stuff.
Was this review helpful?
Was this review helpful?
14 people found this review funny
Extremely boring game with endless highways, only played it for a few hours before I got bored of it.
Was this review helpful?
So this is the most relaxing non-competive driving simulator ever to be created. I wake up turn on my pc, get some food, setup my steering wheel, pedals and gearstick and im trucking for the rest of the day. Totally recommend this game if you just want to relax no stress, no whiny females, just you, your truck and A lot of roads to drive over ?
Was this review helpful?
5 people found this review funny
If your looking for a review on this game you've come to the wrong place, but if your looking for an outstanding lemon bars recipe you've come to the right place.Ingredients:1) 2 cups Flour2) 1/2 cup Sugar3) 1/4 teaspoon Salt4) 2 sticks (1 Cup) Salted Butter, Cut Into Small Cubes5) Filling6) 1-1/2 cup Sugar7) 1/4 cup Flour8) 4 whole Large Eggs9) Zest And Juice Of 4 Medium-sized Lemons10) Powdered Sugar, For SiftingDirections:1. For the crust: Preheat the oven to 350 degrees F. Grease a 9-by-13-inch pan with butter.2. Stir together the flour, sugar, and salt. Add the butter to the bowl and use a pastry cutter to cut it all together until the mixture resembles fine crumbs. Press into the prepared pan and bake until golden around the edges, about 20 minutes.3. For the filling: Stir together the sugar and flour. Crack in the eggs and whisk to combine. Add the lemon zest and juice and mix until combined. Pour over the crust and bake about 20 minutes.4. Allow to cool in the fridge for a minimum of 2 hours, then sift powdered sugar over the top before cutting into squares.(Use an 8 x 10 pan if you'd like the layers to be a little thicker.)
Was this review helpful?
It's a veritable godsend for people with agaraphobia.
Was this review helpful?
Euro Truck Simulator 2 will forever be one of my favorite games. I have put in hundreds of hours, and I still find that I have fun every time I decide to hop in the cab and play
Was this review helpful?
You can use this widget-maker to generate a bit of HTML that can be embedded in your website to easily allow customers to purchase this game on Steam.
There is more than one way to buy this game. Please select a specific package to create a widget for:
Euro Truck Simulator 2
Euro Truck Simulator 2 - East Expansion Bundle
Euro Truck Simulator 2 - North Expansion Bundle
Euro Truck Simulator 2 - Deluxe Bundle
Euro Truck Simulator 2 - Trucking Fan DLC Bundle
Euro Truck Simulator 2 - East + North Expansions
Enter up to 375 characters to add a description to your widget:
Copy and paste the HTML below into your website to make the above widget appear
Share:& & &
VAT included in all prices where applicable.&&
View mobile websiteTime Series / Date functionality & pandas 0.15.2 documentation
Navigation
pandas provides a relatively compact and self-contained set of tools for
performing the above tasks.
Create a range of dates:
# 72 hours starting with midnight Jan 1st, 2011
In [1]: rng = date_range('1/1/2011', periods=72, freq='H')
In [2]: rng[:5]
&class 'pandas.tseries.index.DatetimeIndex'&
[ 00:00:00, ...,
Length: 5, Freq: H, Timezone: None
Index pandas objects with dates:
In [3]: ts = Series(randn(len(rng)), index=rng)
In [4]: ts.head()
Freq: H, dtype: float64
Change frequency and fill gaps:
# to 45 minute frequency and forward fill
In [5]: converted = ts.asfreq('45Min', method='pad')
In [6]: converted.head()
Freq: 45T, dtype: float64
# Daily means
In [7]: ts.resample('D', how='mean')
Freq: D, dtype: float64
However, in many cases it is more natural to associate things like change
variables with a time span instead.
For example:
In [12]: periods = PeriodIndex([Period(';), Period(';),
Period(';)])
In [13]: ts = Series(np.random.randn(3), periods)
In [14]: type(ts.index)
Out[14]: pandas.tseries.period.PeriodIndex
In [15]: ts
Freq: M, dtype: float64
Starting with 0.8, pandas allows you to capture both representations and
convert between them. Under the hood, pandas represents timestamps using
instances of Timestamp and sequences of timestamps using instances of
DatetimeIndex. For regular time spans, pandas uses Period objects for
scalar values and PeriodIndex for sequences of spans. Better support for
irregular intervals with arbitrary start and end points are forth-coming in
future releases.
If you use dates which start with the day first (i.e. European style),
you can pass the dayfirst flag:
In [18]: to_datetime(['04-01-'], dayfirst=True)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 10:00:00]
Length: 1, Freq: None, Timezone: None
In [19]: to_datetime(['14-01-2012', '01-14-2012'], dayfirst=True)
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 2, Freq: None, Timezone: None
You see in the above example that dayfirst isn’t strict, so if a date
can’t be parsed with the day being first it will be parsed as if
dayfirst were False.
Specifying a format argument will potentially speed up the conversion
considerably and on versions later then 0.13.0 explicitly specifying
a format string of ‘%Y%m%d’ takes a faster path still.
Invalid Data
Pass coerce=True to convert invalid data to NaT (not a time):
In [20]: to_datetime(['', 'asd'])
Out[20]: array(['', 'asd'], dtype=object)
In [21]: to_datetime(['', 'asd'], coerce=True)
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 2, Freq: None, Timezone: None
Take care, to_datetime may not act as you expect on mixed data:
In [22]: to_datetime([1, '1'])
Out[22]: array([1, '1'], dtype=object)
These work, but the results may be unexpected.
In [25]: to_datetime([1])
&class 'pandas.tseries.index.DatetimeIndex'&
[ 00:00:00.]
Length: 1, Freq: None, Timezone: None
In [26]: to_datetime([1, 3.14], unit='s')
&class 'pandas.tseries.index.DatetimeIndex'&
[ 00:00:01,
00:00:03.140000]
Length: 2, Freq: None, Timezone: None
Epoch times will be rounded to the nearest nanosecond.
Practically, this becomes very cumbersome because we often need a very long
index with a large number of timestamps. If we need timestamps on a regular
frequency, we can use the pandas functions date_range and bdate_range
to create timestamp indexes.
In [32]: index = date_range('', periods=1000, freq='M')
In [33]: index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 1000, Freq: M, Timezone: None
In [34]: index = bdate_range('', periods=250)
In [35]: index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 250, Freq: B, Timezone: None
Convenience functions like date_range and bdate_range utilize a
variety of frequency aliases. The default frequency for date_range is a
calendar day while the default for bdate_range is a business day
In [36]: start = datetime(2011, 1, 1)
In [37]: end = datetime(2012, 1, 1)
In [38]: rng = date_range(start, end)
In [39]: rng
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 366, Freq: D, Timezone: None
In [40]: rng = bdate_range(start, end)
In [41]: rng
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 260, Freq: B, Timezone: None
date_range and bdate_range makes it easy to generate a range of dates
using various combinations of parameters like start, end,
periods, and freq:
In [42]: date_range(start, end, freq='BM')
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 12, Freq: BM, Timezone: None
In [43]: date_range(start, end, freq='W')
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 53, Freq: W-SUN, Timezone: None
In [44]: bdate_range(end=end, periods=20)
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 20, Freq: B, Timezone: None
In [45]: bdate_range(start=start, periods=20)
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 20, Freq: B, Timezone: None
The start and end dates are strictly inclusive. So it will not generate any
dates outside of those dates if specified.
DatetimeIndex objects has all the basic functionality of regular Index objects
and a smorgasbord of advanced timeseries-specific methods for easy frequency
processing.
While pandas does not force you to have a sorted date index, some of these
methods may have unexpected or incorrect behavior if the dates are
unsorted. So please be careful.
DatetimeIndex can be used like a regular index and offers all of its
intelligent functionality like selection, slicing, etc.
In [46]: rng = date_range(start, end, freq='BM')
In [47]: ts = Series(randn(len(rng)), index=rng)
In [48]: ts.index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 12, Freq: BM, Timezone: None
In [49]: ts[:5].index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 5, Freq: BM, Timezone: None
In [50]: ts[::2].index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 6, Freq: 2BM, Timezone: None
To provide convenience for accessing longer time series, you can also pass in
the year or year and month as strings:
In [54]: ts['2011']
Freq: BM, dtype: float64
In [55]: ts[';]
Freq: BM, dtype: float64
This type of slicing will work on a DataFrame with a DateTimeIndex as well. Since the
partial string selection is a form of label slicing, the endpoints will be included. This
would include matching times on an included date. Here’s an example:
In [56]: dft = DataFrame(randn(100000,1),columns=['A'],index=date_range(';,periods=100000,freq='T'))
In [57]: dft
00:02:00 -0.154951
00:04:00 -2.179861
00:05:00 -1.369849
00:06:00 -0.954208
10:33:00 -0.293083
10:34:00 -0.059881
10:38:00 -0.286539
[100000 rows x 1 columns]
In [58]: dft['2013']
00:02:00 -0.154951
00:04:00 -2.179861
00:05:00 -1.369849
00:06:00 -0.954208
10:33:00 -0.293083
10:34:00 -0.059881
10:38:00 -0.286539
[100000 rows x 1 columns]
This starts on the very first time in the month, and includes the last date & time for the month
In [59]: dft[';:';]
00:02:00 -0.154951
00:04:00 -2.179861
00:05:00 -1.369849
00:06:00 -0.954208
23:54:00 -1.303422
23:57:00 -1.624220
23:59:00 -1.087454
[84960 rows x 1 columns]
This specifies a stop time that includes all of the times on the last day
In [60]: dft[';:'']
00:02:00 -0.154951
00:04:00 -2.179861
00:05:00 -1.369849
00:06:00 -0.954208
23:54:00 -1.303422
23:57:00 -1.624220
23:59:00 -1.087454
[84960 rows x 1 columns]
This specifies an exact stop time (and is not the same as the above)
In [61]: dft[';:' 00:00:00']
00:02:00 -0.154951
00:04:00 -2.179861
00:05:00 -1.369849
00:06:00 -0.954208
23:55:00 -0.309230
23:59:00 -0.019734
[83521 rows x 1 columns]
We are stopping on the included end-point as its part of the index
In [62]: dft['':' 12:30:00']
00:01:00 -0.605198
00:04:00 -2.228519
00:06:00 -1.188774
12:25:00 -0.737727
12:27:00 -0.774090
12:29:00 -0.631649
[751 rows x 1 columns]
The following selection will raise a KeyError; otherwise this selection methodology
would be inconsistent with other selection methods in pandas (as this is not a slice, nor does it
resolve to one)
dft[' 12:30:00']
To select a single row, use .loc
In [63]: dft.loc[' 12:30:00']
12:30:00, dtype: float64
With no defaults.
In [65]: dft[datetime(2013, 1, 1, 10, 12, 0):datetime(2013, 2, 28, 10, 12, 0)]
10:12:00 -0.246733
10:13:00 -1.429225
10:14:00 -1.265339
10:16:00 -0.818200
10:08:00 -0.490372
10:12:00 -0.945450
[83521 rows x 1 columns]
Truncating & Fancy Indexing
A truncate convenience function is provided that is equivalent to slicing:
In [66]: ts.truncate(before='10/31/2011', after='12/31/2011')
Freq: BM, dtype: float64
Even complicated fancy indexing that breaks the DatetimeIndex’s frequency
regularity will result in a DatetimeIndex (but frequency is lost):
In [67]: ts[[0, 2, 6]].index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 3, Freq: None, Timezone: None
We could have done the same thing with DateOffset:
In [70]: from pandas.tseries.offsets import *
In [71]: d + DateOffset(months=4, days=5)
Out[71]: Timestamp(' 09:00:00')
The key features of a DateOffset object are:
it can be added / subtracted to/from a datetime object to obtain a
shifted date
it can be multiplied by an integer (positive or negative) so that the
increment will be applied multiple times
it has rollforward and rollback methods for moving a date forward
or backward to the next or previous “offset date”
Subclasses of DateOffset define the apply function which dictates
custom date increment logic, such as adding business days:
class BDay(DateOffset):
&&&DateOffset increments between business days&&&
def apply(self, other):
In [72]: d - 5 * BDay()
Out[72]: Timestamp(' 09:00:00')
In [73]: d + BMonthEnd()
Out[73]: Timestamp(' 09:00:00')
The rollforward and rollback methods do exactly what you would expect:
In [74]: d
Out[74]: datetime.datetime(2008, 8, 18, 9, 0)
In [75]: offset = BMonthEnd()
In [76]: offset.rollforward(d)
Out[76]: Timestamp(' 09:00:00')
In [77]: offset.rollback(d)
Out[77]: Timestamp(' 09:00:00')
It’s definitely worth exploring the pandas.tseries.offsets module and the
various docstrings for the classes.
These operations (apply, rollforward and rollback) preserves time (hour, minute, etc) information by default. To reset time, use normalize=True keyword when create offset instance. If normalize=True, result is normalized after the function is applied.
In [78]: day = Day()
In [79]: day.apply(Timestamp(' 09:00'))
Out[79]: Timestamp(' 09:00:00')
In [80]: day = Day(normalize=True)
In [81]: day.apply(Timestamp(' 09:00'))
Out[81]: Timestamp(' 00:00:00')
In [82]: hour = Hour()
In [83]: hour.apply(Timestamp(' 22:00'))
Out[83]: Timestamp(' 23:00:00')
In [84]: hour = Hour(normalize=True)
In [85]: hour.apply(Timestamp(' 22:00'))
Out[85]: Timestamp(' 00:00:00')
In [86]: hour.apply(Timestamp(' 23:00'))
Out[86]: Timestamp(' 00:00:00')
Parametric offsets
Some of the offsets can be “parameterized” when created to result in different
behavior. For example, the Week offset for generating weekly data accepts a
weekday parameter which results in the generated dates always lying on a
particular day of the week:
In [87]: d
Out[87]: datetime.datetime(2008, 8, 18, 9, 0)
In [88]: d + Week()
Out[88]: Timestamp(' 09:00:00')
In [89]: d + Week(weekday=4)
Out[89]: Timestamp(' 09:00:00')
In [90]: (d + Week(weekday=4)).weekday()
Out[90]: 4
In [91]: d - Week()
Out[91]: Timestamp(' 09:00:00')
normalize option will be effective for addition and subtraction.
In [92]: d + Week(normalize=True)
Out[92]: Timestamp(' 00:00:00')
In [93]: d - Week(normalize=True)
Out[93]: Timestamp(' 00:00:00')
Another example is parameterizing YearEnd with the specific ending month:
In [94]: d + YearEnd()
Out[94]: Timestamp(' 09:00:00')
In [95]: d + YearEnd(month=6)
Out[95]: Timestamp(' 09:00:00')
Custom Business Days (Experimental)
The CDay or CustomBusinessDay class provides a parametric
BusinessDay class which can be used to create customized business day
calendars which account for local holidays and local weekend conventions.
In [96]: from pandas.tseries.offsets import CustomBusinessDay
# As an interesting example, let's look at Egypt where
# a Friday-Saturday weekend is observed.
In [97]: weekmask_egypt = 'Sun Mon Tue Wed Thu'
# They also observe International Workers' Day so let's
# add that for a couple of years
In [98]: holidays = ['', datetime(2013, 5, 1), np.datetime64('')]
In [99]: bday_egypt = CustomBusinessDay(holidays=holidays, weekmask=weekmask_egypt)
In [100]: dt = datetime(2013, 4, 30)
In [101]: dt + 2 * bday_egypt
Out[101]: Timestamp(' 00:00:00')
In [102]: dts = date_range(dt, periods=5, freq=bday_egypt)
In [103]: Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split()))
Freq: C, dtype: object
As of v0.14 holiday calendars can be used to provide the list of holidays.
section for more information.
In [104]: from pandas.tseries.holiday import USFederalHolidayCalendar
In [105]: bday_us = CustomBusinessDay(calendar=USFederalHolidayCalendar())
# Friday before MLK Day
In [106]: dt = datetime(2014, 1, 17)
# Tuesday after MLK Day (Monday is skipped because it's a holiday)
In [107]: dt + bday_us
Out[107]: Timestamp(' 00:00:00')
Monthly offsets that respect a certain holiday calendar can be defined
in the usual way.
In [108]: from pandas.tseries.offsets import CustomBusinessMonthBegin
In [109]: bmth_us = CustomBusinessMonthBegin(calendar=USFederalHolidayCalendar())
# Skip new years
In [110]: dt = datetime(2013, 12, 17)
In [111]: dt + bmth_us
Out[111]: Timestamp(' 00:00:00')
# Define date index with custom offset
In [112]: from pandas import DatetimeIndex
In [113]: DatetimeIndex(start=';,end=';,freq=bmth_us)
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 24, Freq: CBMS, Timezone: None
The frequency string ‘C’ is used to indicate that a CustomBusinessDay
DateOffset is used, it is important to note that since CustomBusinessDay is
a parameterised type, instances of CustomBusinessDay may differ and this is
not detectable from the ‘C’ frequency string. The user therefore needs to
ensure that the ‘C’ frequency string is used consistently within the user’s
application.
This uses the numpy.busdaycalendar API introduced in Numpy 1.7 and
therefore requires Numpy 1.7.0 or newer.
There are known problems with the timezone handling in Numpy 1.7 and users
should therefore use this experimental(!) feature with caution and at
their own risk.
To the extent that the datetime64 and busdaycalendar APIs in Numpy
have to change to fix the timezone issues, the behaviour of the
CustomBusinessDay class may have to change in future versions.
Offset Aliases
A number of string aliases are given to useful common time series
frequencies. We will refer to these aliases as offset aliases
(referred to as time rules prior to v0.8.0).
business day frequency
custom business day frequency (experimental)
calendar day frequency
weekly frequency
month end frequency
business month end frequency
custom business month end frequency
month start frequency
business month start frequency
custom business month start frequency
quarter end frequency
business quarter endfrequency
quarter start frequency
business quarter start frequency
year end frequency
business year end frequency
year start frequency
business year start frequency
hourly frequency
minutely frequency
secondly frequency
milliseonds
microseconds
nanoseconds
Combining Aliases
As we have seen previously, the alias and the offset instance are fungible in
most functions:
In [114]: date_range(start, periods=5, freq='B')
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 5, Freq: B, Timezone: None
In [115]: date_range(start, periods=5, freq=BDay())
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 5, Freq: B, Timezone: None
You can combine together day and intraday offsets:
In [116]: date_range(start, periods=10, freq='2h20min')
&class 'pandas.tseries.index.DatetimeIndex'&
[ 00:00:00, ...,
Length: 10, Freq: 140T, Timezone: None
In [117]: date_range(start, periods=10, freq='1D10U')
&class 'pandas.tseries.index.DatetimeIndex'&
[ 00:00:00, ...,
00:00:00.000090]
Length: 10, Freq: U, Timezone: None
Anchored Offsets
For some frequencies you can specify an anchoring suffix:
weekly frequency (sundays). Same as ‘W’
weekly frequency (mondays)
weekly frequency (tuesdays)
weekly frequency (wednesdays)
weekly frequency (thursdays)
weekly frequency (fridays)
weekly frequency (saturdays)
(B)Q(S)-DEC
quarterly frequency, year ends in December. Same as ‘Q’
(B)Q(S)-JAN
quarterly frequency, year ends in January
(B)Q(S)-FEB
quarterly frequency, year ends in February
(B)Q(S)-MAR
quarterly frequency, year ends in March
(B)Q(S)-APR
quarterly frequency, year ends in April
(B)Q(S)-MAY
quarterly frequency, year ends in May
(B)Q(S)-JUN
quarterly frequency, year ends in June
(B)Q(S)-JUL
quarterly frequency, year ends in July
(B)Q(S)-AUG
quarterly frequency, year ends in August
(B)Q(S)-SEP
quarterly frequency, year ends in September
(B)Q(S)-OCT
quarterly frequency, year ends in October
(B)Q(S)-NOV
quarterly frequency, year ends in November
(B)A(S)-DEC
annual frequency, anchored end of December. Same as ‘A’
(B)A(S)-JAN
annual frequency, anchored end of January
(B)A(S)-FEB
annual frequency, anchored end of February
(B)A(S)-MAR
annual frequency, anchored end of March
(B)A(S)-APR
annual frequency, anchored end of April
(B)A(S)-MAY
annual frequency, anchored end of May
(B)A(S)-JUN
annual frequency, anchored end of June
(B)A(S)-JUL
annual frequency, anchored end of July
(B)A(S)-AUG
annual frequency, anchored end of August
(B)A(S)-SEP
annual frequency, anchored end of September
(B)A(S)-OCT
annual frequency, anchored end of October
(B)A(S)-NOV
annual frequency, anchored end of November
These can be used as arguments to date_range, bdate_range, constructors
for DatetimeIndex, as well as various other timeseries-related functions
in pandas.
Legacy Aliases
Note that prior to v0.8.0, time rules had a slightly different look. pandas
will continue to support the legacy time rules for the time being but it is
strongly recommended that you switch to using the new offset aliases.
As you can see, legacy quarterly and annual frequencies are business quarter
and business year ends. Please also note the legacy time rule for milliseconds
ms versus the new offset alias for month start MS. This means that
offset alias parsing is case sensitive.
Holidays / Holiday Calendars
Holidays and calendars provide a simple way to define holiday rules to be used
with CustomBusinessDay or in other analysis that requires a predefined
set of holidays.
The AbstractHolidayCalendar class provides all the necessary
methods to return a list of holidays and only rules need to be defined
in a specific holiday calendar class.
Further, start_date and end_date
class attributes determine over what date range holidays are generated.
should be overwritten on the AbstractHolidayCalendar class to have the range
apply to all calendar subclasses.
USFederalHolidayCalendar is the
only calendar that exists and primarily serves as an example for developing
other calendars.
For holidays that occur on fixed dates (e.g., US Memorial Day or July 4th) an
observance rule determines when that holiday is observed if it falls on a weekend
or some other non-observed day.
Defined observance rules are:
nearest_workday
move Saturday to Friday and Sunday to Monday
sunday_to_monday
move Sunday to following Monday
next_monday_or_tuesday
move Saturday to Monday and Sunday/Monday to Tuesday
previous_friday
move Saturday and Sunday to previous Friday”
next_monday
move Saturday and Sunday to following Monday
An example of how holidays and holiday calendars are defined:
In [118]: from pandas.tseries.holiday import Holiday, USMemorialDay,\
AbstractHolidayCalendar, nearest_workday, MO
In [119]: class ExampleCalendar(AbstractHolidayCalendar):
USMemorialDay,
Holiday('July 4th', month=7, day=4, observance=nearest_workday),
Holiday('Columbus Day', month=10, day=1,
offset=DateOffset(weekday=MO(2))), #same as 2*Week(weekday=2)
In [120]: cal = ExampleCalendar()
In [121]: cal.holidays(datetime(2012, 1, 1), datetime(2012, 12, 31))
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 3, Freq: None, Timezone: None
Using this calendar, creating an index or doing offset arithmetic skips weekends
and holidays (i.e., Memorial Day/July 4th).
In [122]: DatetimeIndex(start='7/1/2012', end='7/10/2012',
freq=CDay(calendar=cal)).to_pydatetime()
array([datetime.datetime(, 0, 0),
datetime.datetime(, 0, 0),
datetime.datetime(, 0, 0),
datetime.datetime(, 0, 0),
datetime.datetime(, 0, 0),
datetime.datetime(, 0, 0)], dtype=object)
In [123]: offset = CustomBusinessDay(calendar=cal)
In [124]: datetime(2012, 5, 25) + offset
Out[124]: Timestamp(' 00:00:00')
In [125]: datetime(2012, 7, 3) + offset
Out[125]: Timestamp(' 00:00:00')
In [126]: datetime(2012, 7, 3) + 2 * offset
Out[126]: Timestamp(' 00:00:00')
In [127]: datetime(2012, 7, 6) + offset
Out[127]: Timestamp(' 00:00:00')
Ranges are defined by the start_date and end_date class attributes
of AbstractHolidayCalendar.
The defaults are below.
In [128]: AbstractHolidayCalendar.start_date
Out[128]: Timestamp(' 00:00:00')
In [129]: AbstractHolidayCalendar.end_date
Out[129]: Timestamp(' 00:00:00')
These dates can be overwritten by setting the attributes as
datetime/Timestamp/string.
In [130]: AbstractHolidayCalendar.start_date = datetime(2012, 1, 1)
In [131]: AbstractHolidayCalendar.end_date = datetime(2012, 12, 31)
In [132]: cal.holidays()
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 3, Freq: None, Timezone: None
Every calendar class is accessible by name using the get_calendar function
which returns a holiday class instance.
Any imported calendar class will
automatically be available by this function.
Also, HolidayCalendarFactory
provides an easy interface to create calendars that are combinations of calendars
or calendars with additional rules.
In [133]: from pandas.tseries.holiday import get_calendar, HolidayCalendarFactory,\
USLaborDay
In [134]: cal = get_calendar('ExampleCalendar')
In [135]: cal.rules
[Holiday: MemorialDay (month=5, day=24, offset=&DateOffset: kwds={'weekday': MO(+1)}&),
Holiday: July 4th (month=7, day=4, observance=&function nearest_workday at 0x9fbbc684&),
Holiday: Columbus Day (month=10, day=1, offset=&DateOffset: kwds={'weekday': MO(+2)}&)]
In [136]: new_cal = HolidayCalendarFactory('NewExampleCalendar', cal, USLaborDay)
In [137]: new_cal.rules
[Holiday: Labor Day (month=9, day=1, offset=&DateOffset: kwds={'weekday': MO(+1)}&),
Holiday: Columbus Day (month=10, day=1, offset=&DateOffset: kwds={'weekday': MO(+2)}&),
Holiday: July 4th (month=7, day=4, observance=&function nearest_workday at 0x9fbbc684&),
Holiday: MemorialDay (month=5, day=24, offset=&DateOffset: kwds={'weekday': MO(+1)}&)]
The shift method accepts an freq argument which can accept a
DateOffset class or other timedelta-like object or also a :
In [140]: ts.shift(5, freq=datetools.bday)
dtype: float64
In [141]: ts.shift(5, freq='BM')
Freq: BM, dtype: float64
Rather than changing the alignment of the data and the index, DataFrame and
TimeSeries objects also have a tshift convenience method that changes
all the dates in the index by a specified number of offsets:
In [142]: ts.tshift(5, freq='D')
dtype: float64
Note that with tshift, the leading entry is no longer NaN because the data
is not being realigned.
Frequency conversion
The primary function for changing frequencies is the asfreq function.
For a DatetimeIndex, this is basically just a thin, but convenient wrapper
around reindex which generates a date_range and calls reindex.
In [143]: dr = date_range('1/1/2010', periods=3, freq=3 * datetools.bday)
In [144]: ts = Series(randn(3), index=dr)
In [145]: ts
Freq: 3B, dtype: float64
In [146]: ts.asfreq(BDay())
Freq: B, dtype: float64
asfreq provides a further convenience so you can specify an interpolation
method for any gaps that may appear after the frequency conversion
In [147]: ts.asfreq(BDay(), method='pad')
Freq: B, dtype: float64
Filling forward / backward
Related to asfreq and reindex is the fillna function documented in
Up- and downsampling
With 0.8, pandas introduces simple, powerful, and efficient functionality for
performing resampling operations during frequency conversion (e.g., converting
secondly data into 5-minutely data). This is extremely common in, but not
limited to, financial applications.
for some advanced strategies
In [148]: rng = date_range('1/1/2012', periods=100, freq='S')
In [149]: ts = Series(randint(0, 500, len(rng)), index=rng)
In [150]: ts.resample('5Min', how='sum')
Freq: 5T, dtype: int32
The resample function is very flexible and allows you to specify many
different parameters to control the frequency conversion and resampling
operation.
The how parameter can be a function name or numpy array function that takes
an array and produces aggregated values:
In [151]: ts.resample('5Min') # default is mean
Freq: 5T, dtype: float64
In [152]: ts.resample('5Min', how='ohlc')
In [153]: ts.resample('5Min', how=np.max)
Freq: 5T, dtype: int32
Any function available via
can be given to
the how parameter by name, including sum, mean, std, sem,
max, min, median, first, last, ohlc.
For downsampling, closed can be set to ‘left’ or ‘right’ to specify which
end of the interval is closed:
In [154]: ts.resample('5Min', closed='right')
308.000000
250.454545
Freq: 5T, dtype: float64
In [155]: ts.resample('5Min', closed='left')
Freq: 5T, dtype: float64
For upsampling, the fill_method and limit parameters can be specified
to interpolate over the gaps that are created:
# from secondly to every 250 milliseconds
In [156]: ts[:2].resample('250L')
00:00:00.250000
00:00:00.500000
00:00:00.750000
Freq: 250L, dtype: float64
In [157]: ts[:2].resample('250L', fill_method='pad')
00:00:00.250000
00:00:00.500000
00:00:00.750000
Freq: 250L, dtype: int32
In [158]: ts[:2].resample('250L', fill_method='pad', limit=2)
00:00:00.250000
00:00:00.500000
00:00:00.750000
Freq: 250L, dtype: float64
Parameters like label and loffset are used to manipulate the resulting
labels. label specifies whether the result is labeled with the beginning or
the end of the interval. loffset performs a time adjustment on the output
In [159]: ts.resample('5Min') # by default label='right'
Freq: 5T, dtype: float64
In [160]: ts.resample('5Min', label='left')
Freq: 5T, dtype: float64
In [161]: ts.resample('5Min', label='left', loffset='1s')
dtype: float64
The axis parameter can be set to 0 or 1 and allows you to resample the
specified axis for a DataFrame.
kind can be set to ‘timestamp’ or ‘period’ to convert the resulting index
to/from time-stamp and time-span representations. By default resample
retains the input representation.
convention can be set to ‘start’ or ‘end’ when resampling period data
(detail below). It specifies how low frequency periods are converted to higher
frequency periods.
Note that 0.8 marks a watershed in the timeseries functionality in pandas. In
previous versions, resampling had to be done using a combination of
date_range, groupby with asof, and then calling an aggregation
function on the grouped object. This was not nearly convenient or performant as
the new pandas timeseries API.
Unlike time stamped data, pandas does not support frequencies at multiples of
DateOffsets (e.g., ‘3Min’) for periods.
Adding and subtracting integers from periods shifts the period by its own
frequency.
In [165]: p = Period('2012', freq='A-DEC')
In [166]: p + 1
Out[166]: Period('2013', 'A-DEC')
In [167]: p - 3
Out[167]: Period('2009', 'A-DEC')
If Period freq is daily or higher (D, H, T, S, L, U, N), offsets and timedelta-like can be added if the result can have same freq. Otherise, ValueError will be raised.
In [168]: p = Period(' 09:00', freq='H')
In [169]: p + Hour(2)
Out[169]: Period(' 11:00', 'H')
In [170]: p + timedelta(minutes=120)
Out[170]: Period(' 11:00', 'H')
In [171]: p + np.timedelta64(7200, 's')
Out[171]: Period(' 11:00', 'H')
In [1]: p + Minute(5)
ValueError: Input has different freq from Period(freq=H)
If Period has other freqs, only the same offsets can be added. Otherwise, ValueError will be raised.
In [172]: p = Period(';, freq='M')
In [173]: p + MonthEnd(3)
Out[173]: Period(';, 'M')
In [1]: p + MonthBegin(3)
ValueError: Input has different freq from Period(freq=M)
Taking the difference of Period instances with the same frequency will
return the number of frequency units between them:
In [174]: Period('2012', freq='A-DEC') - Period('2002', freq='A-DEC')
Out[174]: 10L
PeriodIndex and period_range
Regular sequences of Period objects can be collected in a PeriodIndex,
which can be constructed using the period_range convenience function:
In [175]: prng = period_range('1/1/2011', '1/1/2012', freq='M')
In [176]: prng
&class 'pandas.tseries.period.PeriodIndex'&
[2011-01, ..., 2012-01]
Length: 13, Freq: M
The PeriodIndex constructor can also be used directly:
In [177]: PeriodIndex([';, ';, ';], freq='M')
&class 'pandas.tseries.period.PeriodIndex'&
[2011-01, ..., 2011-03]
Length: 3, Freq: M
Just like DatetimeIndex, a PeriodIndex can also be used to index pandas
In [178]: ps = Series(randn(len(prng)), prng)
In [179]: ps
Freq: M, dtype: float64
PeriodIndex supports addition and subtraction as the same rule as Period.
In [180]: idx = period_range(' 09:00', periods=5, freq='H')
In [181]: idx
&class 'pandas.tseries.period.PeriodIndex'&
[ 09:00, ...,
Length: 5, Freq: H
In [182]: idx + Hour(2)
&class 'pandas.tseries.period.PeriodIndex'&
[ 11:00, ...,
Length: 5, Freq: H
In [183]: idx = period_range(';, periods=5, freq='M')
In [184]: idx
&class 'pandas.tseries.period.PeriodIndex'&
[2014-07, ..., 2014-11]
Length: 5, Freq: M
In [185]: idx + MonthEnd(3)
&class 'pandas.tseries.period.PeriodIndex'&
[2014-10, ..., 2015-02]
Length: 5, Freq: M
PeriodIndex Partial String Indexing
You can pass in dates and strings to Series and DataFrame with PeriodIndex, as the same manner as DatetimeIndex. For details, refer to .
In [186]: ps[';]
Out[186]: -0.92818
In [187]: ps[datetime(2011, 12, 25):]
Freq: M, dtype: float64
In [188]: ps['10/31/2011':'12/31/2011']
Freq: M, dtype: float64
Passing string represents lower frequency than PeriodIndex returns partial sliced data.
In [189]: ps['2011']
Freq: M, dtype: float64
In [190]: dfp = DataFrame(randn(600,1), columns=['A'],
index=period_range(' 9:00', periods=600, freq='T'))
In [191]: dfp
09:01 -0.411719
09:03 -1.077911
09:05 -0.089851
18:53 -1.340038
18:56 -0.501527
18:57 -3.171938
[600 rows x 1 columns]
In [192]: dfp[' 10H']
10:00 -0.745396
10:02 -1.077754
10:03 -1.301174
10:04 -0.269628
10:05 -0.456347
10:54 -0.214306
10:55 -0.069739
10:56 -1.511809
[60 rows x 1 columns]
As the same as DatetimeIndex, the endpoints will be included in the result. Below example slices data starting from 10:00 to 11:59.
In [193]: dfp[' 10H':' 11H']
10:00 -0.745396
10:02 -1.077754
10:03 -1.301174
10:04 -0.269628
10:05 -0.456347
11:53 -0.064395
11:56 -0.438701
11:57 -0.915841
[120 rows x 1 columns]
Frequency Conversion and Resampling with PeriodIndex
The frequency of Periods and PeriodIndex can be converted via the asfreq
method. Let’s start with the fiscal year 2011, ending in December:
In [194]: p = Period('2011', freq='A-DEC')
In [195]: p
Out[195]: Period('2011', 'A-DEC')
We can convert it to a monthly frequency. Using the how parameter, we can
specify whether to return the starting or ending month:
In [196]: p.asfreq('M', how='start')
Out[196]: Period(';, 'M')
In [197]: p.asfreq('M', how='end')
Out[197]: Period(';, 'M')
The shorthands ‘s’ and ‘e’ are provided for convenience:
In [198]: p.asfreq('M', 's')
Out[198]: Period(';, 'M')
In [199]: p.asfreq('M', 'e')
Out[199]: Period(';, 'M')
Converting to a “super-period” (e.g., annual frequency is a super-period of
quarterly frequency) automatically returns the super-period that includes the
input period:
In [200]: p = Period(';, freq='M')
In [201]: p.asfreq('A-NOV')
Out[201]: Period('2012', 'A-NOV')
Note that since we converted to an annual frequency that ends the year in
November, the monthly period of December 2011 is actually in the 2012 A-NOV
Q-DEC define regular calendar quarters:
In [202]: p = Period(';, freq='Q-DEC')
In [203]: p.asfreq('D', 's')
Out[203]: Period('', 'D')
In [204]: p.asfreq('D', 'e')
Out[204]: Period('', 'D')
Q-MAR defines fiscal year end in March:
In [205]: p = Period(';, freq='Q-MAR')
In [206]: p.asfreq('D', 's')
Out[206]: Period('', 'D')
In [207]: p.asfreq('D', 'e')
Out[207]: Period('', 'D')
Converting between Representations
Timestamped data can be converted to PeriodIndex-ed data using to_period
and vice-versa using to_timestamp:
In [208]: rng = date_range('1/1/2012', periods=5, freq='M')
In [209]: ts = Series(randn(len(rng)), index=rng)
In [210]: ts
Freq: M, dtype: float64
In [211]: ps = ts.to_period()
In [212]: ps
Freq: M, dtype: float64
In [213]: ps.to_timestamp()
Freq: MS, dtype: float64
Remember that ‘s’ and ‘e’ can be used to return the timestamps at the start or
end of the period:
In [214]: ps.to_timestamp('D', how='s')
Freq: MS, dtype: float64
Converting between period and timestamp enables some convenient arithmetic
functions to be used. In the following example, we convert a quarterly
frequency with year ending in November to 9am of the end of the month following
the quarter end:
In [215]: prng = period_range(';, ';, freq='Q-NOV')
In [216]: ts = Series(randn(len(prng)), prng)
In [217]: ts.index = (prng.asfreq('M', 'e') + 1).asfreq('H', 's') + 9
In [218]: ts.head()
Freq: H, dtype: float64
Representing out-of-bounds spans
If you have data that is outside of the Timestamp bounds, see ,
then you can use a PeriodIndex and/or Series of Periods to do computations.
In [219]: span = period_range('', '', freq='D')
In [220]: span
&class 'pandas.tseries.period.PeriodIndex'&
Length: 60632, Freq: D
To convert from a int64 based YYYYMMDD representation.
In [221]: s = Series([, , ])
In [222]: s
dtype: int64
In [223]: def conv(x):
return Period(year = x // 10000, month = x//100 % 100, day = x%100, freq='D')
In [224]: s.apply(conv)
dtype: object
In [225]: s.apply(conv)[2]
Out[225]: Period('', 'D')
These can easily be converted to a PeriodIndex
In [226]: span = PeriodIndex(s.apply(conv))
In [227]: span
&class 'pandas.tseries.period.PeriodIndex'&
Length: 3, Freq: D
To supply the time zone, you can use the tz keyword to date_range and
other functions. Dateutil time zone strings are distinguished from pytz
time zones by starting with dateutil/.
In pytz you can find a list of common (and less common) time zones using
from pytz import common_timezones, all_timezones.
dateutil uses the OS timezones so there isn’t a fixed list available. For
common zones, the names are the same as pytz.
In [230]: rng_pytz = date_range('3/6/', periods=10, freq='D',
tz='Europe/London')
In [231]: rng_pytz.tz
Out[231]: &DstTzInfo 'Europe/London' LMT-1 day, 23:59:00 STD&
# dateutil
In [232]: rng_dateutil = date_range('3/6/', periods=10, freq='D',
tz='dateutil/Europe/London')
In [233]: rng_dateutil.tz
Out[233]: tzfile('Europe/London')
# dateutil - utc special case
In [234]: rng_utc = date_range('3/6/', periods=10, freq='D',
tz=dateutil.tz.tzutc())
In [235]: rng_utc.tz
Out[235]: tzutc()
Note that the UTC timezone is a special case in dateutil and should be constructed explicitly
as an instance of dateutil.tz.tzutc. You can also construct other timezones explicitly first,
which gives you more control over which time zone is used:
In [236]: tz_pytz = pytz.timezone('Europe/London')
In [237]: rng_pytz = date_range('3/6/', periods=10, freq='D',
tz=tz_pytz)
In [238]: rng_pytz.tz == tz_pytz
Out[238]: True
# dateutil
In [239]: tz_dateutil = dateutil.tz.gettz('Europe/London')
In [240]: rng_dateutil = date_range('3/6/', periods=10, freq='D',
tz=tz_dateutil)
In [241]: rng_dateutil.tz == tz_dateutil
Out[241]: True
Timestamps, like Python’s datetime.datetime object can be either time zone
naive or time zone aware. Naive time series and DatetimeIndex objects can be
localized using tz_localize:
In [242]: ts = Series(randn(len(rng)), rng)
In [243]: ts_utc = ts.tz_localize('UTC')
In [244]: ts_utc
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
Freq: D, dtype: float64
Again, you can explicitly construct the timezone object first.
You can use the tz_convert method to convert pandas objects to convert
tz-aware data to another time zone:
In [245]: ts_utc.tz_convert('US/Eastern')
19:00:00-05:00
19:00:00-05:00
19:00:00-05:00
19:00:00-05:00
19:00:00-05:00
19:00:00-05:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
20:00:00-04:00
Freq: D, dtype: float64
Be wary of conversions between libraries. For some zones pytz and dateutil have different
definitions of the zone. This is more of a problem for unusual timezones than for
‘standard’ zones like US/Eastern.
Be aware that a timezone definition across versions of timezone libraries may not
be considered equal.
This may cause problems when working with stored data that
is localized using one version and operated on with a different version.
for how to handle such a situation.
It is incorrect to pass a timezone directly into the datetime.datetime constructor (e.g.,
datetime.datetime(2011, 1, 1, tz=timezone('US/Eastern')).
Instead, the datetime
needs to be localized using the the localize method on the timezone.
Under the hood, all timestamps are stored in UTC. Scalar values from a
DatetimeIndex with a time zone will have their fields (day, hour, minute)
localized to the time zone. However, timestamps with the same UTC value are
still considered to be equal even if they are in different time zones:
In [246]: rng_eastern = rng_utc.tz_convert('US/Eastern')
In [247]: rng_berlin = rng_utc.tz_convert('Europe/Berlin')
In [248]: rng_eastern[5]
Out[248]: Timestamp(' 19:00:00-0500', tz='US/Eastern', offset='D')
In [249]: rng_berlin[5]
Out[249]: Timestamp(' 01:00:00+0100', tz='Europe/Berlin', offset='D')
In [250]: rng_eastern[5] == rng_berlin[5]
Out[250]: True
Like Series, DataFrame, and DatetimeIndex, Timestamps can be converted to other
time zones using tz_convert:
In [251]: rng_eastern[5]
Out[251]: Timestamp(' 19:00:00-0500', tz='US/Eastern', offset='D')
In [252]: rng_berlin[5]
Out[252]: Timestamp(' 01:00:00+0100', tz='Europe/Berlin', offset='D')
In [253]: rng_eastern[5].tz_convert('Europe/Berlin')
Out[253]: Timestamp(' 01:00:00+0100', tz='Europe/Berlin')
Localization of Timestamps functions just like DatetimeIndex and TimeSeries:
In [254]: rng[5]
Out[254]: Timestamp(' 00:00:00', offset='D')
In [255]: rng[5].tz_localize('Asia/Shanghai')
Out[255]: Timestamp(' 00:00:00+0800', tz='Asia/Shanghai')
Operations between TimeSeries in different time zones will yield UTC
TimeSeries, aligning the data on the UTC timestamps:
In [256]: eastern = ts_utc.tz_convert('US/Eastern')
In [257]: berlin = ts_utc.tz_convert('Europe/Berlin')
In [258]: result = eastern + berlin
In [259]: result
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
00:00:00+00:00
Freq: D, dtype: float64
In [260]: result.index
&class 'pandas.tseries.index.DatetimeIndex'&
Length: 15, Freq: D, Timezone: UTC
To remove timezone from tz-aware DatetimeIndex, use tz_localize(None) or tz_convert(None).
tz_localize(None) will remove timezone holding local time representations.
tz_convert(None) will remove timezone after converting to UTC time.
In [261]: didx = DatetimeIndex(start=' 09:00', freq='H', periods=10, tz='US/Eastern')
In [262]: didx
&class 'pandas.tseries.index.DatetimeIndex'&
[ 09:00:00-04:00, ...,
18:00:00-04:00]
Length: 10, Freq: H, Timezone: US/Eastern
In [263]: didx.tz_localize(None)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 09:00:00, ...,
Length: 10, Freq: H, Timezone: None
In [264]: didx.tz_convert(None)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 13:00:00, ...,
Length: 10, Freq: H, Timezone: None
# tz_convert(None) is identical with tz_convert('UTC').tz_localize(None)
In [265]: didx.tz_convert('UCT').tz_localize(None)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 13:00:00, ...,
Length: 10, Freq: H, Timezone: None
In addition to ‘infer’, there are several other arguments supported.
an array-like of bools or 0s/1s where True represents a DST hour and False a
non-DST hour, allows for distinguishing more than one DST
transition (e.g., if you have multiple records in a database each with their
own DST transition).
Or passing ‘NaT’ will fill in transition times
with not-a-time values.
These methods are available in the DatetimeIndex
constructor as well as tz_localize.
In [270]: rng_hourly_dst = np.array([1, 1, 0, 0, 0])
In [271]: rng_hourly.tz_localize('US/Eastern', ambiguous=rng_hourly_dst).tolist()
[Timestamp(' 00:00:00-0400', tz='US/Eastern'),
Timestamp(' 01:00:00-0400', tz='US/Eastern'),
Timestamp(' 01:00:00-0500', tz='US/Eastern'),
Timestamp(' 02:00:00-0500', tz='US/Eastern'),
Timestamp(' 03:00:00-0500', tz='US/Eastern')]
In [272]: rng_hourly.tz_localize('US/Eastern', ambiguous='NaT').tolist()
[Timestamp(' 00:00:00-0400', tz='US/Eastern'),
Timestamp(' 02:00:00-0500', tz='US/Eastern'),
Timestamp(' 03:00:00-0500', tz='US/Eastern')]
In [273]: didx = DatetimeIndex(start=' 09:00', freq='H', periods=10, tz='US/Eastern')
In [274]: didx
&class 'pandas.tseries.index.DatetimeIndex'&
[ 09:00:00-04:00, ...,
18:00:00-04:00]
Length: 10, Freq: H, Timezone: US/Eastern
In [275]: didx.tz_localize(None)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 09:00:00, ...,
Length: 10, Freq: H, Timezone: None
In [276]: didx.tz_convert(None)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 13:00:00, ...,
Length: 10, Freq: H, Timezone: None
# tz_convert(None) is identical with tz_convert('UTC').tz_localize(None)
In [277]: didx.tz_convert('UCT').tz_localize(None)
&class 'pandas.tseries.index.DatetimeIndex'&
[ 13:00:00, ...,
Length: 10, Freq: H, Timezone: None
Navigation}

我要回帖

更多关于 g4385返程 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信