{"id":30669051,"url":"https://github.com/ts-kontakt/interpareto","last_synced_at":"2025-09-01T01:02:49.545Z","repository":{"id":305126214,"uuid":"1021997594","full_name":"ts-kontakt/interpareto","owner":"ts-kontakt","description":"Python utility for creating interactive Pareto charts from pandas.DataFrame objects","archived":false,"fork":false,"pushed_at":"2025-07-25T10:25:53.000Z","size":1157,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-29T05:28:02.357Z","etag":null,"topics":["data-visualization","html-export","pandas","plotly"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ts-kontakt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-18T09:32:10.000Z","updated_at":"2025-07-25T10:25:56.000Z","dependencies_parsed_at":"2025-07-18T13:42:00.743Z","dependency_job_id":"fe37f5e8-8fd5-4920-b826-a2cc58c34e9d","html_url":"https://github.com/ts-kontakt/interpareto","commit_stats":null,"previous_names":["ts-kontakt/interpareto"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ts-kontakt/interpareto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-kontakt%2Finterpareto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-kontakt%2Finterpareto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-kontakt%2Finterpareto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-kontakt%2Finterpareto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ts-kontakt","download_url":"https://codeload.github.com/ts-kontakt/interpareto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-kontakt%2Finterpareto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273060932,"owners_count":25038594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-visualization","html-export","pandas","plotly"],"created_at":"2025-09-01T01:01:17.131Z","updated_at":"2025-09-01T01:02:49.537Z","avatar_url":"https://github.com/ts-kontakt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InterPareto: Pandas DataFrames to Interactive Pareto Analysis\n[![Downloads](https://img.shields.io/pypi/dm/interpareto.svg)](https://pypi.org/project/interpareto/) [![PyPI version](https://img.shields.io/pypi/v/interpareto.svg)](https://pypi.org/project/interpareto/)\n\n\n`interpareto` is a Python utility for easy creating interactive Pareto charts from `pandas.DataFrame` objects. It generates standalone HTML files with dynamic visualizations using [Plotly.js](https://plotly.com/javascript/)—viewable in any browser without Jupyter notebooks, servers, or frameworks.\n\nThe result is an **interactive chart**, where the data column used in the plot can be switched.\n\nExample that uses well known movie dataset.\n\n![Movies dataset](https://github.com/ts-kontakt/interpareto/blob/main/interpareto_movies.gif?raw=true)\n\n📌  **Note**\n\n**InterPareto doesn’t use Plotly for Python or any server to run.**\nInstead, it generates standalone HTML files with embedded interactive charts using Plotly.js (JavaScript).\nNo server, Jupyter, or browser rendering engine is required at runtime.\n\n\n[Live example](https://www.stockmap.pl/pareto_example.html)\n\nThis design allows charts to be:\n- Viewed offline in any modern web browser,\n- Embedded into web apps if needed.\n\n### Installation\n```pip install interpareto```\n\n## Quick start\n```python\nimport pandas as pd\nimport interpareto as ipar\nsample_df = ipar.generate_pareto_data(100)\nipar.render(sample_df, title=\"Sample Data Analysis\")\n```\n\nOf course, not all datasets are suitable for this kind of analysis — but many are.\n### Ideal for analyzing:\n- Positive numeric values (sales, defects, costs)\n- Skewed distributions (few large, many small values)\n- Categorical data with measurable impact\n- Data w- here the 80/20 principle may apply\n \n### Avoid using with:\n- Normally distributed data\n- Data with many zero/negative values\n- Data without clear categories\n\n## Features\n- Converts `pandas.DataFrame` to interactive standalone HTML Pareto charts\n- **Dynamic column selection**: Switch between different data columns in real-time\n- **Smart data processing**: Automatically detects and removes index-like columns\n- **Data cleaning**: Handles NaN values, negatives, and zeros with detailed reporting\n- Self-contained HTML files with embedded data—no external dependencies at runtime\n- Works independently of web servers—viewable offline in any browser\n- **Minimal HTML snippet generation**: Generate embeddable HTML content for Flask or other web frameworks\n\n## Basic usage\n\n```python\nimport pandas as pd\n\nimport interpareto as ipar\n\n# Simple example with 15 data points\ndf = pd.DataFrame({\n    \"Product\": [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\"],\n    \"Sales\": [5000, 3200, 2800, 2100, 1900, 1500, 1200, 900, 750, 650, 500, 400, 300, 200, 150],\n    \"Profit\": [1200, 800, 333, 222, 40, 111, 100, 90, 12, 60, 60, 55, 45, 12, 2]\n})\n\n# Generate chart\nipar.render(df, title=\"Sales Analysis\", to_file=\"sales_pareto.html\")\n```\nPareto analysis is based on the Pareto Principle (80/20 rule), which states that roughly 80% of effects come from 20% of causes. InterPareto automatically:\n\n- **Sorts data**: Orders values from highest to lowest\n- **Calculates cumulative percentages**: Shows running totals as percentage of whole\n- **Identifies the 80% threshold**: Highlights where 80% of total value is reached\n- **Annotates key insights**: Shows what percentage of categories contribute to 80% of value\n\n\n## Main Functions\n\n### render\n\n```python\nipar.render(\n    df: pd.DataFrame,\n    to_file: Optional[str] = None,\n    title: str = \"Pareto dashboard\",\n    templ_path: str = TEMPLATE_PATH,\n    startfile: bool = True,\n    warnings: bool = True\n) -\u003e Union[str, file_object]\n```\n\n**Parameters:**\n- `df`: Input pandas DataFrame with numeric columns for analysis\n- `to_file`: Output HTML file path. If None, returns HTML string instead of writing file\n- `title`: Title for the Pareto dashboard\n- `templ_path`: Path to custom HTML template (uses default if not specified)\n- `startfile`: If True, automatically opens the generated HTML file in default browser\n- `warnings`: If True, displays data processing warnings in the output\n\n**Returns:**\n- HTML string if `to_file=None`\n- File object if `to_file` is specified\n\n### render_inline\n\n```python\nipar.render_inline(\n    df: pd.DataFrame,\n    **kwargs\n) -\u003e str\n```\n\nGenerates minimal HTML content suitable for embedding in Flask or other web framework templates. This function:\n- Returns only the chart markup and JavaScript\n- Excludes full HTML document structure (no `\u003chtml\u003e`, `\u003chead\u003e`, `\u003cbody\u003e` tags)\n- **Important**: Requires Plotly.js to be loaded in the host page\n- Perfect for embedding interactive Pareto analysis in existing web applications\n\n**Parameters:**\n- Same as `render()` except `to_file` is not allowed (always returns string)\n\n### generate_pareto_data\n\n```python\nipar.generate_pareto_data(N: int = 15) -\u003e pd.DataFrame\n```\n\nGenerates sample data following various statistical distributions for testing and demonstration purposes.\n\n**Parameters:**\n- `N`: Number of data points to generate\n\n**Returns:**\n- DataFrame with sample data including Pareto, normal, uniform, and other distributions\n\n### Automatic Data Cleaning\n\nInterPareto automatically processes your data to ensure optimal visualization:\n\n- **Index-like column detection**: Removes columns that appear to be indices or sequential numbers\n- **Duplicate index handling**: Removes duplicate row indices, keeping the first occurrence\n- **Numeric column selection**: Automatically selects the first 10 numeric columns\n- **Missing value handling**: Removes rows with NaN values\n- **Negative and zero filtering**: Excludes rows with negative values or zeros (configurable)\n\n\n### Processing Warnings\n\nThe library provides detailed feedback about data processing:\n\n```python\n# Example processing output\n\"\"\"\nDropped column 'ID': looks like index\nColumn 'Revenue': 2 NaNs, (1 negative values, 3 zeros)\nColumn 'Customers': 0 NaNs, (0 negative values, 1 zeros)\n\"\"\"\n```\n\n## Web Framework Integration\n\n### Complete Flask Example\n\nHere's a complete Flask application demonstrating how to embed interactive Pareto charts:\n\n```python\nfrom flask import Flask, render_template_string\nimport interpareto as ipar\n\napp = Flask(__name__)\n\n@app.route(\"/\")\ndef home():\n    # Generate sample data (or use your own DataFrame)\n    df = ipar.generate_pareto_data(50)\n    \n    df_title = \"Pareto Chart Rendered inline in \u003cstrong\u003eFlask\u003c/strong\u003e\"\n    \n    # Generate the embeddable Pareto chart HTML\n    string_pareto = ipar.render_inline(df, title=df_title, warnings=False)\n    \n    return render_template_string(\n        \"\"\"\n        \u003c!DOCTYPE html\u003e\n        \u003chtml\u003e\n        \u003chead\u003e\n            \u003ctitle\u003eFlask Pareto Dashboard\u003c/title\u003e\n            \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n            \n            \u003c!-- Required: Plotly.js for chart rendering --\u003e\n            \u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.26.0/plotly.min.js\"\u003e\u003c/script\u003e\n            \n            \u003cstyle\u003e\n                body {\n                    font-family: \"Segoe UI\", Roboto, sans-serif;\n                    margin: 0;\n                    padding: 20px;\n                    background-color: #f8f9fa;\n                }\n                .container {\n                    max-width: 1200px;\n                    margin: 0 auto;\n                    background: white;\n                    padding: 20px;\n                    border-radius: 8px;\n                    box-shadow: 0 2px 10px rgba(0,0,0,0.1);\n                }\n                h1 {\n                    color: #333;\n                    text-align: center;\n                    margin-bottom: 30px;\n                }\n            \u003c/style\u003e\n        \u003c/head\u003e\n        \u003cbody\u003e\n            \u003cdiv class=\"container\"\u003e\n                \u003ch1\u003eMy Flask Pareto Dashboard\u003c/h1\u003e\n                {{ inline_pareto | safe }}\n            \u003c/div\u003e\n        \u003c/body\u003e\n        \u003c/html\u003e\n        \"\"\",\n        inline_pareto=string_pareto,\n    )\n\nif __name__ == \"__main__\":\n    app.run(debug=True)\n```\n\n## Understanding Pareto Analysis\n\n### Chart Components\n\nThe generated Pareto chart includes:\n\n1. **Horizontal bar chart**: Shows individual values for each category\n2. **Cumulative line**: Displays running percentage total\n3. **80% threshold line**: Horizontal dashed line at 80%\n4. **Intersection annotation**: Shows where cumulative line crosses 80%\n5. **Dynamic controls**: Dropdown to switch between different data columns\n\n### Customization Examples\n\n📌  **Note**\nCurrently, modifying chart colors or settings is possible by editing the built-in HTML/JS template or by using a custom template.\n\nNote that the goal of this module is not to replicate  functionality of Plotly for Python when it comes to customization.\n\n\n```python\n# Use custom template\nipar.render(\n    df,\n    title=\"Branded Analysis\",\n    templ_path=\"custom_pareto_template.html\",\n    to_file=\"branded_pareto.html\"\n)\n\n# Generate sample data for testing\nsample_df = ipar.generate_pareto_data(100)\nipar.render(sample_df, title=\"Sample Data Analysis\")\n```\n\n## Requirements\n\n- Python 3.7+\n- pandas\n- numpy\n  \n### Chart Features\n\n- **Interactive tooltips**: Hover for detailed information\n- **Column switching**: Real-time data column selection\n- **Export options**: Built-in Plotly export functionality\n- **Zoom and pan**: Interactive chart exploration\n\n### Template System\n\nTemplates use [comnt](https://github.com/ts-kontakt/comnt), a minimal markup system:\n\n```html\n\u003c!--[title--\u003e\nDashboard Title\n\u003c!--title]--\u003e\n\nconst data = /*[p_data*/ [...] /*p_data]*/;\n```\n\nMIT License  \n© Tomasz Sługocki\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-kontakt%2Finterpareto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fts-kontakt%2Finterpareto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-kontakt%2Finterpareto/lists"}