Halloween Sale: Flat 70% + Addl. 25% Off + 30 Days Extra Lab on all Courses | Use Coupon HS25 in Checkout | Offer Expires In

  Enroll Now

Setting the Index for the Data Frame

Since we are dealing with time-series data, it makes sense to see the date column as the index of our data frame.

We shall do this by using the set_index method on the df_yahoo data frame.

But before that, let us first convert the "date" column into DateTime type using the pd.to_datetime() method of pandas.

Note:

  • pd.to_datetime() is used to covert the type of column to datetime type.

  • set_index() method is used to set the data frame index using existing columns.

INSTRUCTIONS
  • Convert the "date" column of the df_yahoo data frame into datetime type using pd.datetime().

     df_yahoo['date']= pd.<< your code comes here >>(df_yahoo['date'])
    
  • View the type of "date" column of df_yahoo data frame using dtype.

     print(df_yahoo.date.dtype)
    

    Observe the type of the column was previously "object", whereas it is of type "datetime64[ns]".

  • Now, set the "date" column as the index of df_yahoo data frame using the set_index() method.

    df_yahoo = df_yahoo.<< your code comes here >>("date")
    
  • View the top 5 rows of df_yahoo data frame using head() method.

    df_yahoo.<< your code comes here >>()
    

No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...