Skip to content

Commit

Permalink
Merge branch 'm-kovalsky/issue246'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Nov 11, 2024
2 parents 4c0fc3d + fecf4da commit c5fbd05
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/sempy_labs/_vertipaq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Optional
from sempy._utils._log import log
import sempy_labs._icons as icons
from pathlib import Path


@log
Expand Down Expand Up @@ -412,18 +413,19 @@ def vertipaq_analyzer(
export_Model = dfModel.copy()

def _style_columns_based_on_types(dataframe: pd.DataFrame, column_type_mapping):

format_mapping = {
"int": "{:,}",
"pct": "{:.2f}%",
"": "{}",
# Define formatting functions based on the type mappings
format_funcs = {
"int": lambda x: "{:,}".format(x) if pd.notnull(x) else "",
"pct": lambda x: "{:.2f}%".format(x) if pd.notnull(x) else "",
"": lambda x: "{}".format(x),
}

format_dict = {
col: format_mapping[dt] for col, dt in column_type_mapping.items()
}
# Apply the formatting function to each column based on its specified type
for col, dt in column_type_mapping.items():
if dt in format_funcs:
dataframe[col] = dataframe[col].map(format_funcs[dt])

return dataframe.style.format(format_dict)
return dataframe

dfModel = _style_columns_based_on_types(
dfModel,
Expand Down Expand Up @@ -979,7 +981,9 @@ def import_vertipaq_analyzer(folder_path: str, file_name: str):
dfs = {}
for file_name in zip_ref.namelist():
df = pd.read_csv(extracted_dir + "/" + file_name)
dfs[file_name] = df
file_path = Path(file_name)
df_name = file_path.stem
dfs[df_name] = df

visualize_vertipaq(dfs)

Expand Down

0 comments on commit c5fbd05

Please sign in to comment.