CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-sweetviz

A pandas-based library to visualize and compare datasets.

Overview
Eval results
Files

report-display.mddocs/

Report Generation and Display

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.

Capabilities

HTML Report Generation

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)
    """

Usage Examples

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
)

Notebook Integration

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
    """

Usage Examples

# 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
)

Experiment Tracking Integration

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)
    """

Usage Examples

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 configured

Layout Options

Widescreen Layout

  • Best for: Desktop displays, detailed analysis
  • Features: Side-by-side detail panels, hover interactions
  • Default for: HTML reports

Vertical Layout

  • Best for: Narrow screens, mobile devices, notebook cells
  • Features: Stacked panels, click to expand details
  • Default for: Notebook displays

Configuration Defaults

Reports 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 = 700

Display Parameters

Width and Height (Notebook)

  • Percentage: w="100%" - Relative to container
  • Pixels: w=800, h=600 - Absolute dimensions
  • Full Height: h="Full" - Expands to content height

Scale Parameter

  • Range: Floating-point values (e.g., 0.5 to 2.0)
  • Default: 1.0 (100% size)
  • Common values: 0.8 (compact), 1.2 (larger)

File Output

  • All display methods can optionally save HTML files
  • Use filepath parameter for concurrent display and save
  • Use file_layout and file_scale for different file settings

Error Handling

Display 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}")

Performance Considerations

  • Large Reports: Use scale parameter to reduce memory usage
  • Notebook Memory: Limit dimensions for large datasets
  • File Size: HTML reports include all data and can be large
  • Browser Performance: Very large reports may be slow to render

Install with Tessl CLI

npx tessl i tessl/pypi-sweetviz

docs

configuration.md

core-analysis.md

index.md

report-display.md

tile.json