6.3. database
- class nettoolkit.nettoolkit_db.database.XL_READ(xl, sheet_name=None)[source]
Bases:
object
reads an existing Excel file provide absolute path along with filename as xl provide sheet_name in order to read only a particular sheet only. otherwise all sheets will be read and stored under df_dict attribute.
- Returns:
XL_READ object
- Return type:
self
- Yields:
sheet, DataFrame – sheet by sheet data
- class nettoolkit.nettoolkit_db.database.XL_WRITE(name, df_dict, index=False, overwrite=False, index_label='')[source]
Bases:
object
write to an Excel file
- Returns:
XL_WRITE object
- Return type:
self
- copy_of_file(file, n)[source]
return a valid next available file name.
- Parameters:
file (str) – name of file
n (int) – name suffix
- Returns:
available filename to make a new copy of file.
- Return type:
str
- get_valid_file_name(file)[source]
gets a valid next available filename and create a copy of provided file.
- Parameters:
file (str) – name of file
- Returns:
next available file name (after coping file)
- Return type:
str
- write(name, df_dict, index, index_label, overwrite)[source]
method to start write to file. by default it will run while initialize of object
- Parameters:
name (str) – file name with absolute path and extension
df_dict (dict) – dictionary of dataframes
index (bool, optional) – write index column or not. Defaults to False.
index_label (str, optional) – index label
overwrite (bool, optional) – overwrite the file (if exist) or not. Defaults to False.
- nettoolkit.nettoolkit_db.database.append_to_xl(file, df_dict, overwrite=True, index_label='')[source]
appends dictionary of dataframes to an Excel file overwrite: will append data to existing file, else create a copy and adds data to it
- Parameters:
file (str) – input excel filename
df_dict (dict) – dictionary of key:DataFrame format
overwrite (bool, optional) – overwrite or append. Defaults to True.
index_label (str, optional) – index label for each tab
- nettoolkit.nettoolkit_db.database.get_merged_DataFrame_of_file(file)[source]
returns merged DataFrame after clubbing all tabs of file
- Parameters:
file (str) – Excel file name
- Returns:
merged database
- Return type:
pandas DataFrame
- nettoolkit.nettoolkit_db.database.read_xl(file)[source]
reads Excel file and return object XL_READ
- Parameters:
file (str) – input excel filename
- Returns:
XL_READ object (pandas DataFrame parent)
- Return type:
- nettoolkit.nettoolkit_db.database.sort_dataframe_on_subnet(df, col, ascending=True)[source]
sort provided dataframe on the provided subnet column. default ascending order.
- Parameters:
df (DataFrame) – pandas DataFrame
col (str) – subnet column name
ascending (bool, optional) – sort dataframe on ascending subnet order. Defaults to True.
- Returns:
sorted DataFrame
- Return type:
DataFrame
- nettoolkit.nettoolkit_db.database.write_to_xl(file, df_dict, index=False, overwrite=False, index_label='')[source]
Create a new Excel file with provided dictionary of dataframes overwrite: removes existing file, else create a copy if file exist.
- Parameters:
file (str) – input excel filename
df_dict (dict) – dictionary of key:DataFrame format
index (bool, optional) – keep index column. Defaults to False.
overwrite (bool, optional) – overwrite or create a new file. Defaults to False.
index_label (str, optional) – index label for each tab