Your first time series
You have learned in the video how to create a sequence of dates using pd.date_range()
. You have also seen that each date in the resulting pd.DatetimeIndex
is a pd.Timestamp
with various attributes that you can access to obtain information about the date.
Now, you'll create a week of data, iterate over the result, and obtain the dayofweek
and day_name()
for each date.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have already imported pandas
as pd
for you.
- Use
pd.date_range
to create seven dates starting from'2017-1-1'
at (default) daily frequency. Use the argumentsstart
andperiods
. Assign the result toseven_days
. - Iterate over each date in
seven_days
and in each iteration, print the.dayofweek
and.day_name()
attributes.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the range of dates here
seven_days = ____
# Iterate over the dates and print the number and name of the weekday
for day in ___:
print(___.___, ___.___)