MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Manipulating Time Series Data in Python

Lihat Kursus

Petunjuk latihan

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 arguments start and periods. Assign the result to seven_days.
  • Iterate over each date in seven_days and in each iteration, print the .dayofweek and .day_name() attributes.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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(___.___, ___.___)

Edit dan Jalankan Kode