Skip to content

Implement save_report()

Task: Implement the save_report function.

File: database_management.py

Header:

def save_report(table: pd.DataFrame, file_name: str) -> str

Detailed Breakdown of save_report():

  • Initial Parameters:
    • table: The table to be saved as a CSV
    • file_name: The name of the saved file (without the directory or file extension)
  • Create Path: file_name is joined with a directory and the .csv extension to create the full save_path
  • Formatting: A copy of the table, formatted_table is created, and its values are converted to formatted strings where necessary. These formats are as follows:
    • Dates: MM/DD/YYYY (in local time)
    • Datetimes: MM/DD/YYYY HH:MM (in local time) 
    • Booleans: “True” or “False”
  • Write To File: formatted_table is written to save_path, using the to_csv method from the pandas module. If another report with the same name exists, that report is overwritten. 
  • Return Path: save_path is returned.

Notes:

A little test of gitlab's issue functionality.