Manipulating Dates by Adding Time Intervals
Explore how to manipulate dates by adding or subtracting time intervals with Pandas DateOffset and Timedelta functions. Understand different units and methods to adjust date and time data efficiently.
We'll cover the following...
We'll cover the following...
The DateOffset function
One Pandas function we can use to add or subtract dates and times is DateOffset. It can be used with both dates and times. We only need to specify the unit and quantity to be added or subtracted. Consider a case where we want to give a raise to our employees one year after they’re hired. In the staff, we can create a column called raise_date by adding one year to the start_date column.
The DateOffset function is quite simple. We only need to adjust the unit and quantity. For instance, the following line of code adds six months to the ...