How it works...
In this recipe, we extracted the date and time parts of a datetime variable. We first created a toy dataframe with a variable that contained both the date and time in its values. To create the toy dataframe, we used the pandas date_range() method to create a range of values starting from an arbitrary date and increasing this by intervals of 1 minute. With the periods argument, we indicated the number of values to create in the range, that is, the number of dates; and with the freq argument, we indicated the size of the steps between the dates—we used T for minutes in our example. Finally, we transformed the date range into a dataframe with the pandas DataFrame() method.
With pandas' head(), we displayed the first five rows ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access