otld.append.TANFData.TANFData

class otld.append.TANFData.TANFData(type: str, appended_path: str, to_append_path: str | list[str], sheets: dict[list] = {}, footnotes: dict[list[list]] = {}, tableau: bool = False)

Bases: object

Class to manage appending TANF caseload and financial data

__init__(type: str, appended_path: str, to_append_path: str | list[str], sheets: dict[list] = {}, footnotes: dict[list[list]] = {}, tableau: bool = False)

Initialize TANFData class

Args:

type (str): Type of data being appended. Takes one of financial or caseload. appended_path (str): Path to the appended file. Should be xlsx format. to_append_path (str | list[str]): Path to the file or files to append. Should be xlsx format. sheets (dict[list], optional): A dictionary of sheets to extract. Defaults to {}.

Methods

__init__(type, appended_path, to_append_path)

Initialize TANFData class

append()

Append financial or caseload data

close_excel_files()

Close all files

export_workbook()

Export data to Excel workbook

get_current_sheet()

Return the current sheet

get_df()

Get data from file to append

get_header_wrapper(df)

Wrapper for get_header

get_worksheets()

Get worksheets that correspond to the current level

identify_workbook_level(path)

Identify the level of the caseload workbook

load_data(to_append_path)

Load TANF data to append

rename_columns()

Rename the columns in TANFData._df

set_sheets([sheets])

Set sheet_dict

validate_data_frame()

Wraps validate_data_frame; Ensures a copy is used

Attributes

appended

Base file containing appended data

footnotes

Any footnotes to include in the final files

sheet_dict

Dictionary of sheets from which to extract information

tableau

Boolean indicating whether tableau-specific datasets should be output

to_append

File, or list of files, to append to base file

type

The kind of data being appended

append()

Append financial or caseload data

property appended

Base file containing appended data

close_excel_files()

Close all files

export_workbook()

Export data to Excel workbook

property footnotes

Any footnotes to include in the final files

get_current_sheet()

Return the current sheet

get_df()

Get data from file to append

Args:

level (str): The current funding level. worksheet (str): The worksheet to extract data from.

get_header_wrapper(df: DataFrame) DataFrame

Wrapper for get_header

Re-runs with the concatenate option if the header has duplicates, numeric columns or the data frame is empty

Args:

df (pd.DataFrame): DataFrame to search in for a header.

Returns:

pd.DataFrame: DataFrame columns renamed and any leading columns dropped.

get_worksheets()

Get worksheets that correspond to the current level

identify_workbook_level(path: str)

Identify the level of the caseload workbook

load_data(to_append_path: str | list[str])

Load TANF data to append

Args:

to_append_path (str | list[str]): File or list of files to append.

Raises:

TypeError: If to_append path is not a string or list of strings.

rename_columns()

Rename the columns in TANFData._df

set_sheets(sheets: dict = {})

Set sheet_dict

Args:

sheets (dict, optional): A dictionary of sheets. Defaults to {}.

property sheet_dict

Dictionary of sheets from which to extract information

property tableau

Boolean indicating whether tableau-specific datasets should be output

property to_append

File, or list of files, to append to base file

property type

The kind of data being appended

validate_data_frame()

Wraps validate_data_frame; Ensures a copy is used