9.4. A few Database operations

Interacting with Excel Database

Lets first import all available functions from nettoolkit_db

>>> from nettoolkit.nettoolkit_db import *

Available Functions

9.4.1. get_merged_DataFrame_of_file()

  • returns merged DataFrame after clubbing all tabs of file

  • all tabs should contain identical columns in order to merge them

>>> file = "inputfile.xlsx"
>>> df = get_merged_DataFrame_of_file(file)

9.4.2. append_to_xl()

  • appends dictionary of dataframes to an Excel file, existing tabs will be retained, if different

  • overwrite: will append data to existing file, else create a copy and adds data to it

  • index_label: to set the index label for each tab, None else

>>> d = {"Sheet_A": DataFrame_A, "Sheet_B": DataFrame_B, "Sheet_C": DataFrame_C,}
>>> append_to_xl('output_file.xlsx', d)

9.4.3. write_to_xl()

  • Create a new Excel file with provided dictionary of dataframes

  • overwrite: removes existing file, else create a copy if file exist

  • index: boolean value, to mention about index column requirement

  • index_label: to set the index label for each tab, None else

>>> d = {"Sheet_A": DataFrame_A, "Sheet_B": DataFrame_B, "Sheet_C": DataFrame_C,}
>>> write_to_xl('output_file.xlsx', d)

9.4.4. sort_dataframe_on_subnet()

  • sort provided dataframe on the provided subnet column. default ascending order

>>> df = pd.DataFrame({"Col_A":['colA Values', ..], "Subnet":['subnets values', ..],  "Col_C":['colC Values', ..],    })
>>> sorted_df = sort_dataframe_on_subnet(df, col="Subnet")