建立 timedelta 欄位
在本課前面,你寫過一個迴圈來相減 datetime 物件,判斷我們的範例腳踏車離開停靠站多久。現在你要用 Pandas 做同樣的事。
rides 已為你載入。
本練習屬於課程
在 Python 處理日期與時間
練習說明
- 以
End date欄減去Start date欄,取得一個由 timedelta 組成的 Series;將結果指派給ride_durations。 - 將
ride_durations轉換為秒數,並把結果指派到rides的「Duration」欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Subtract the start date from the end date
ride_durations = ____ - ____
# Convert the results to seconds
____[____] = ride_durations.____
print(rides['Duration'].head())