From the course: Data Analysis with Python and Pandas
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Solution: Time deltas
From the course: Data Analysis with Python and Pandas
Solution: Time deltas
- [Instructor] Alright, everybody. Our solution code is up on the right. Let's go ahead and dive into the notebook. Alright, and so we started with this table here, and the first thing that we wanted to do was add three weeks to our "time_to_last_date" column. So we're calling the "assign" method on our "transactions" data frame, creating a column called "time_to_last_date". We're just going to overwrite the existing "time_ to_last_date" column, and we're going to specify "pd.to_timedelta". We want to add three weeks. We could also do 21 days here as well. Either way, you'll get the same solution. And we're just going to add this "timedelta" to our existing "time_to_last_date" column, which is going to return the column that has 21 more day s than it did before. For the second piece, and of course, we can always break this out into multiple steps, but we're using our lambda trick here. So we want to create a column based off of this updated "time_to_last_date" column. So we want to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Times in Python and pandas3m 8s
-
(Locked)
Converting to datetimes6m 16s
-
(Locked)
Formatting dates5m 20s
-
(Locked)
Date and time parts3m 4s
-
(Locked)
Challenge: pandas datetime basics1m 23s
-
(Locked)
Solution: pandas datetime basics2m 10s
-
(Locked)
Time deltas and arithmetic6m 54s
-
(Locked)
Challenge: Time deltas1m 10s
-
(Locked)
Solution: Time deltas1m 29s
-
(Locked)
Time series indices3m 58s
-
(Locked)
Missing time series data4m 45s
-
(Locked)
Challenge: Missing time series data1m 44s
-
(Locked)
Solution: Missing time series data2m 13s
-
(Locked)
Shifting time series3m 16s
-
(Locked)
Pro tip: diff()2m 54s
-
(Locked)
Challenge: shift() and diff()1m 39s
-
(Locked)
Solution: shift() and diff()2m 47s
-
(Locked)
Aggregation and resampling4m 6s
-
(Locked)
Challenge: Resampling41s
-
(Locked)
Solution: Resampling1m 53s
-
(Locked)
Rolling aggregations4m 35s
-
(Locked)
Challenge: Rolling aggregations45s
-
(Locked)
Solution: Rolling aggregations55s
-
(Locked)
Key takeaways1m 37s
-
(Locked)
-
-
-