A pandas-based library to visualize and compare datasets.
Methods for rendering and outputting analysis reports in various formats. DataframeReport objects provide multiple output options including HTML files, notebook embedding, and experiment tracking integration.
Generates self-contained HTML reports that can be saved to disk and viewed in web browsers. Provides full interactivity and high-quality visualizations optimized for desktop viewing.
def show_html(self,
filepath: str = 'SWEETVIZ_REPORT.html',
open_browser: bool = True,
layout: str = 'widescreen',
scale: float = None) -> None:
"""
Generate and save an HTML report to disk.
Parameters:
- filepath: Path where HTML file will be saved
- open_browser: Whether to automatically open the report in default browser
- layout: Report layout ('widescreen' or 'vertical')
- scale: Scaling factor for report size (e.g., 0.8 for 80% size)
"""import sweetviz as sv
# Create report
df = pd.read_csv('data.csv')
report = sv.analyze(df)
# Basic HTML output
report.show_html() # Saves to 'SWEETVIZ_REPORT.html'
# Custom filename and path
report.show_html('analysis/my_report.html')
# Vertical layout for narrow screens
report.show_html(layout='vertical')
# Scaled down for smaller displays
report.show_html(scale=0.8)
# Don't auto-open browser (useful in scripts)
report.show_html(open_browser=False)
# Combined options
report.show_html(
filepath='reports/analysis_2024.html',
layout='vertical',
scale=0.9,
open_browser=False
)Embeds reports directly in Jupyter notebooks and similar environments using iframe elements. Provides interactive viewing without leaving the notebook interface.
def show_notebook(self,
w: Union[str, int] = None,
h: Union[str, int] = None,
scale: float = None,
layout: str = None,
filepath: str = None,
file_layout: str = None,
file_scale: float = None) -> None:
"""
Display report inline in Jupyter notebooks.
Parameters:
- w: Width of display window (percentage string like "100%" or pixels)
- h: Height of display window (pixels or "Full" for full height)
- scale: Scaling factor for embedded report
- layout: Report layout ('widescreen' or 'vertical')
- filepath: Optional path to also save HTML file
- file_layout: Layout for optional file output
- file_scale: Scale for optional file output
"""# In Jupyter notebook
import sweetviz as sv
import pandas as pd
df = pd.read_csv('data.csv')
report = sv.analyze(df)
# Basic notebook display
report.show_notebook()
# Custom dimensions
report.show_notebook(w="100%", h=800)
# Vertical layout for narrow cells
report.show_notebook(layout='vertical', scale=0.8)
# Full height display
report.show_notebook(h="Full", w="100%")
# Display in notebook AND save file
report.show_notebook(
w="100%",
h=700,
filepath='backup_report.html'
)
# Different layouts for display vs file
report.show_notebook(
layout='vertical', # For notebook display
filepath='report.html',
file_layout='widescreen', # For saved file
file_scale=1.0
)Integrates with Comet.ml for experiment tracking and collaboration. Automatically logs reports when Comet.ml environment is configured, and provides explicit logging methods.
def log_comet(self, experiment) -> None:
"""
Log report to a Comet.ml experiment.
Parameters:
- experiment: comet_ml.Experiment object
Raises:
Exception: If logging fails (prints error message)
"""import sweetviz as sv
import comet_ml
# Initialize Comet experiment
experiment = comet_ml.Experiment(
api_key="your-api-key",
project_name="data-analysis"
)
# Create and log report
df = pd.read_csv('data.csv')
report = sv.analyze(df, target_feat='outcome')
# Explicit logging
report.log_comet(experiment)
# Automatic logging (when environment configured)
# Reports are automatically logged when using show_html() or show_notebook()
report.show_html() # Also logs to Comet if configuredReports can use custom default settings via configuration files:
# Override default settings
sv.config_parser.read("custom_config.ini")
# Example INI content:
# [Output_Defaults]
# html_layout = vertical
# html_scale = 0.9
# notebook_layout = widescreen
# notebook_scale = 0.8
# notebook_width = 100%
# notebook_height = 700w="100%" - Relative to containerw=800, h=600 - Absolute dimensionsh="Full" - Expands to content heightfilepath parameter for concurrent display and savefile_layout and file_scale for different file settingsDisplay methods may encounter:
# Handle file permission errors
try:
report.show_html('/protected/path/report.html')
except PermissionError:
report.show_html('report.html') # Save in current directory
# Handle invalid layout values
try:
report.show_html(layout='invalid')
except ValueError as e:
print(f"Layout error: {e}")
report.show_html(layout='widescreen') # Use valid layout
# Handle Comet logging issues
try:
report.log_comet(experiment)
except Exception as e:
print(f"Comet logging failed: {e}")scale parameter to reduce memory usageInstall with Tessl CLI
npx tessl i tessl/pypi-sweetviz