October 17, 2020

1750 words 9 mins read



Visualize and compare datasets, target values and associations, with one line of code.

repo name fbdesignpro/sweetviz
repo link https://github.com/fbdesignpro/sweetviz
language Python
size (curr.) 16000 kB
stars (curr.) 1063
created 2020-05-09
license MIT License

v v

Sweetviz Logo

Sweetviz is an open source Python library that generates beautiful, high-density visualizations to kickstart EDA (Exploratory Data Analysis) with a single line of code. Output is a fully self-contained HTML application.

The system is built around quickly visualizing target values and comparing datasets. Its goal is to help quick analysis of target characteristics, training vs testing data, and other such data characterization tasks.

Usage and parameters are described below, you can also find an article describing its features in depth and see examples in action HERE.

October 2020 update: Sweetviz is out of beta and development is still ongoing! Please let me know if you run into any data, compatibility or install issues! Thank you for reporting any BUGS in the issue tracking system here, and I welcome your feedback and questions on usage/features in our forum (you should be able to log in with your Github account!).


Example report from the Titanic dataset



  • Target analysis
    • How target values (boolean or numerical) relate to other features
  • Visualize and compare
    • Distinct datasets (e.g. training vs test data)
    • Intra-set characteristics (e.g. male versus female)
  • Mixed-type associations
    • Sweetviz integrates associations for numerical (Pearson’s correlation), categorical (uncertainty coefficient) and categorical-numerical (correlation ratio) datatypes seamlessly, to provide maximum information for all data types.
  • Type inference: automatically detects numerical, categorical and text features, with optional manual overrides
  • Summary information:
    • Type, unique values, missing values, duplicate rows, most frequent values
    • Numerical analysis:
      • min/max/range, quartiles, mean, mode, standard deviation, sum, median absolute deviation, coefficient of variation, kurtosis, skewness


Some people have experienced mixed results behavior upgrading through pip. To update to the latest from an existing install, it is recommended to pip uninstall sweetviz first, then simply install.


Sweetviz currently supports Python 3.6+ and Pandas 0.25.3+. Reports are output using the base “os” module, so custom environments such as Google Colab which require custom file operations are not yet supported, although I am looking into a solution.

Using pip

The best way to install sweetviz (other than from source) is to use pip:

pip install sweetviz

Installation issues & fixes

In some rare cases, users have reported errors such as ModuleNotFoundError: No module named 'sweetviz' and AttributeError: module 'sweetviz' has no attribute 'analyze'. In those cases, we suggest the following:

  • Make sure none of your scripts are named sweetviz.py, as that interferes with the library itself. Delete or rename that script (and any associated .pyc files), and try again.
  • Try uninstalling the library using pip uninstall sweetviz, then reinstalling
  • The issue may stem from using multiple versions of Python, or from OS permissions. The following Stack Overflow articles have resolved many of these issues reported: Article 1, Article 2, Article 3
  • If all else fails, post a bug issue here on github. Thank you for taking the time, it may help resolve the issue for you and everyone else!

Basic Usage

Creating a report is a quick 2-line process:

  1. Create a DataframeReport object using one of: analyze(), compare() or compare_intra()
  2. Use a show_xxx() function to render the report.

Note: Currently the only rendering supported is to a standalone HTML file, using a “widescreen” aspect ratio (i.e. 1080p resolution or wider). Please let me know of formats/resolutions you would like to be supported in our forum.

Step 1: Create the report

There are 3 main functions for creating reports:

  • analyze(…)
  • compare(…)
  • compare_intra(…)

Analyzing a single dataframe (and its optional target feature)

To analyze a single dataframe, simply use the analyze(...) function, then the show_html(...) function:

import sweetviz as sv

my_report = sv.analyze(my_dataframe)
my_report.show_html() # Default arguments will generate to "SWEETVIZ_REPORT.html"

When run, this will output a 1080p widescreen html app in your default browser: Widescreen demo

Optional arguments

The analyze() function can take multiple other arguments:

analyze(source: Union[pd.DataFrame, Tuple[pd.DataFrame, str]],
            target_feat: str = None,
            feat_cfg: FeatureConfig = None,
            pairwise_analysis: str = 'auto'):
  • source: Either the data frame (as in the example) or a tuple containing the data frame and a name to show in the report. e.g. my_df or [my_df, "Training"]
  • target_feat: A string representing the name of the feature to be marked as “target”. Only BOOLEAN and NUMERICAL features can be targets for now.
  • feat_cfg: A FeatureConfig object representing features to be skipped, or to be forced a certain type in the analysis. The arguments can either be a single string or list of strings. Parameters are skip, force_cat, force_num and force_text. The “force_” arguments override the built-in type detection. They can be constructed as follows:
feature_config = sv.FeatureConfig(skip="PassengerId", force_text=["Age"])
  • pairwise_analysis: Correlations and other associations can take quadratic time (n^2) to complete. The default setting (“auto”) will run without warning until a data set contains “association_auto_threshold” features. Past that threshold, you need to explicitly pass the parameter pairwise_analysis="on" (or ="off") since processing that many features would take a long time. This parameter also covers the generation of the association graphs (based on Drazen Zaric’s concept):

Pairwise sample

Comparing two dataframes (e.g. Test vs Training sets)

To compare two data sets, simply use the compare() function. Its parameters are the same as analyze(), except with an inserted second parameter to cover the comparison dataframe. It is recommended to use the [dataframe, “name”] format of parameters to better differentiate between the base and compared dataframes. (e.g. [my_df, "Train"] vs my_df)

my_report = sv.compare([my_dataframe, "Training Data"], [test_df, "Test Data"], "Survived", feature_config)

Comparing two subsets of the same dataframe (e.g. Male vs Female)

Another way to get great insights is to use the comparison functionality to split your dataset into 2 sub-populations.

Support for this is built in through the compare_intra() function. This function takes a boolean series as one of the arguments, as well as an explicit “name” tuple for naming the (true, false) resulting datasets. Note that internally, this creates 2 separate dataframes to represent each resulting group. As such, it is more of a shorthand function of doing such processing manually.

my_report = sv.compare_intra(my_dataframe, my_dataframe["Sex"] == "male", ["Male", "Female"], feature_config)

Step 2: Show the report

Once you have created your report object (e.g. my_report in the examples above), simply pass it into a show_xxx() function.

Currently the only rendering supported is to a standalone HTML file, using a “widescreen” aspect ratio (i.e. 1080p resolution or wider). Please let me know of formats/resolutions you would like to be supported in our forum.

So currently, simply call the following function with the desired parameters:

my_report.show_html(filepath='SWEETVIZ_REPORT.html', open_browser=True)

The open_browser parameter is a new addition in 1.1 to give the option to avoid opening a browser window once the HTML file is generated.

Config file

The package contains an INI file for configuration. You can override any setting by providing your own then calling this before creating a report:


IMPORTANT #1: it is best to load overrides before any other command, as many of the INI options are used in the report generation.

IMPORTANT #2: always set the header (e.g. [General] before the value, otherwise there will be an error).

Most useful config overrides

You can look into the file sweetviz_defaults.ini for what can be overriden (warning: much of it is a work in progress and not well documented), but the most useful overrides are:

use_cjk_font = 1

show_logo = 0
New: Chinese, Japanse, Korean (CJK) character support
use_cjk_font = 1 

Will switch the font in the graphs to use a CJK-compatible font. Although this font is not as compact, it will get rid of any warnings and “unknown character” symbols for these languages.

show_logo = 0

Will remove the Sweetviz logo from the top of the page.

Troubleshooting / FAQ

  • Installation issues

Please see the “Installation issues & fixes” section at the top of this document

  • Asian characters, “RuntimeWarning: Glyph ### missing from current font”

See section above regarding CJK characters support. If you find the need for additional character types, definitely post a request in the issue tracking system.

  • …any other issues

Development is ongoing so absolutely feel free to report any issues and/or suggestions in the issue tracking system here or in our forum (you should be able to log in with your Github account!)


This is my first open-source project! I built it to be the most useful tool possible and help as many people as possible with their data science work. If it is useful to you, your contribution is more than welcome and can take many forms:

1. Spread the word!

A STAR here on GitHub, and a Twitter or Instagram post are the easiest contribution and can potentially help grow this project tremendously! If you find this project useful, these quick actions from you would mean a lot and could go a long way.

Kaggle notebooks/posts, Medium articles, YouTube video tutorials and other content take more time but will help all the more!

2. Report bugs & issues

I expect there to be many quirks once the project is used by more and more people with a variety of new (& “unclean”) data. If you found a bug, please open a new issue here.

3. Suggest and discuss usage/features

To make Sweetviz as useful as possible we need to hear what you would like it to do, or what it could do better! Head on to our Discourse server and post your suggestions there; no login required!.

4. Contribute to the development

I definitely welcome the help I can get on this project, simply get in touch on the issue tracker and/or our Discourse forum.

Please note that after a hectic development period, the code itself right now needs a bit of cleanup. :)

Special thanks & related materials

I want Sweetviz to be a hub of the best of what’s out there, a way to get the most valuable information and visualization, without reinventing the wheel.

As such, I want to point some of those great resources that were inspiring and integrated into Sweetviz:

And of course, very special thanks to everyone who have contributed on Github, through reports, feedback and commits!

comments powered by Disqus