Skip to content

Commit

Permalink
feat: report comparison example (#1160)
Browse files Browse the repository at this point in the history
* feat: add report comparison example
  • Loading branch information
alexbarros authored and aquemy committed Nov 22, 2022
1 parent 34cf73d commit 5e75fd2
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
120 changes: 120 additions & 0 deletions examples/report_comparison/comparison.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "54253ce4",
"metadata": {
"cell_style": "center"
},
"outputs": [],
"source": [
"# Installed packages\n",
"import pandas as pd\n",
"\n",
"# Our package\n",
"from pandas_profiling import ProfileReport\n",
"from pandas_profiling.utils.cache import cache_file"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "134987f5",
"metadata": {},
"outputs": [],
"source": [
"# Read the Titanic Dataset\n",
"file_name = cache_file(\n",
" \"titanic.csv\",\n",
" \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\",\n",
")\n",
"df = pd.read_csv(file_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21dda1c6",
"metadata": {},
"outputs": [],
"source": [
"# Generate the Profiling Report from 2 samples from titanic dataset\n",
"profile1 = ProfileReport(df.sample(frac=0.5))\n",
"profile2 = ProfileReport(df.sample(frac=0.5))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe83402f",
"metadata": {},
"outputs": [],
"source": [
"# compare the profiles and generate a comparison profile\n",
"comparison = profile1.compare(profile2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ad00f47",
"metadata": {},
"outputs": [],
"source": [
"# display the html profile in an iframe\n",
"comparison"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
20 changes: 20 additions & 0 deletions examples/report_comparison/comparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pandas as pd

from pandas_profiling import ProfileReport
from pandas_profiling.utils.cache import cache_file

if __name__ == "__main__":
# Read the Titanic Dataset
file_name = cache_file(
"titanic.csv",
"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv",
)
df = pd.read_csv(file_name)

# Generate the Profiling Report from 2 samples from titanic dataset
profile1 = ProfileReport(df.sample(frac=0.5))
profile2 = ProfileReport(df.sample(frac=0.5))

# compare the profiles and generate a comparison profile
comparison = profile1.compare(profile2)
comparison.to_file("profile_comparison.html")

0 comments on commit 5e75fd2

Please sign in to comment.