Exercise

Customizing a DataFrame

In your company, any data has to come with a timestamp recording when the dataset was created, to make sure that outdated information is not being used. You would like to use pandas DataFrames for processing data, but you would need to customize the class to allow for the use of timestamps.

In this exercise, you will implement a small LoggedDF class that inherits from a regular pandas DataFrame but has a created_at attribute storing the timestamp. You will then augment the standard to_csv() method to always include a column storing the creation date.

Tip: all DataFrame methods have many parameters, and it is not sustainable to copy all of them for each method you're customizing. The trick is to use variable-length arguments *args and **kwargsto catch all of them.

Instructions 1/2

undefined XP
    1
    2
  • Import pandas as pd.
  • Define LoggedDF class inherited from pd.DataFrame.
  • Define a constructor with arguments *args and **kwargs that:
    • calls the pd.DataFrame constructor with the same arguments,
    • assigns datetime.today() to self.created_at.