Datetime math operations
We have shown already some operations that can be applied to datetime
/Timestamp
objects. In this section, we will go a little deeper and show the use of the origin
parameter, which is useful if converting dates in some integer formats (such as might come from Excel).
Date ranges
Suppose you were provided with some data that is daily temperatures from 1/1/2019 to 6/30/2020 but it is provided as simply a series of values without the corresponding dates. You would like to be able to work with the data corresponding to actual dates, for example, to look for repeating patterns or seasonal variations. You can add the dates easily using the pandas date_range
method:
- Here, you create a
temperatures
series beginning with just an integer series, using the NumPysin()
function and a period of 180 days to generate variation over time, and adding noise to represent the hypothetical data. The first step is to create the integer series:x_values = pd.Series...