# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Install Olliepy

# %%capture
# !pip install -U Olliepy

# # Import pandas and olliepy

import pandas as pd
from olliepy import InteractiveDashboard

# # Import data

df = pd.read_csv('data/sales_data.csv')

df.head()

# # Define columns to be used in the dashbaord

# +
categorical_columns = ['year', 'country', 'region',
                        'remote_sale', 'salesman_position',
                        'product_type', 'product_subtype']

numerical_columns = ['latitude', 'longitude',
                      'number_of_sales','distance_travelled_in_KM',
                      'sales_amount_in_dollars','unit_price']

date_columns = ['date']
# -

# # Generate dashboard using olliepy

dashboard = InteractiveDashboard(title='Sales dashboard',
                                output_directory='.',
                                dashboard_folder_name='SALES_DASHBOARD',
                                dataframes=[df],
                                dataframes_names=['Sales'],
                                numerical_columns=numerical_columns,
                                categorical_columns=categorical_columns,
                                date_columns=date_columns,
                                generate_encryption_secret=False)

# ## (Optional) Bin numerical features to be used in bar, row, pie, heatmap, etc.

dashboard.bin_numerical_feature('number_of_sales', 'number_of_sales_binned', 10, 'n_sales')
dashboard.bin_numerical_feature('distance_travelled_in_KM', 'distance_binned', 10, 'distance')

# ## Create dashboard with histograms and count plots for the provided features

dashboard.create_dashboard(auto_generate_distribution_plots=True)

# ## Serve dashboard and display in a new tab

dashboard.serve_dashboard_from_local_server(mode='server', load_existing_dashboard=False)

# ## Serve dashboard and display in jupyter

dashboard.serve_dashboard_from_local_server(mode='jupyter', load_existing_dashboard=False)

# ## Save dashboard and zip it to share it with someone or display it locally if you are using a cloud solution

dashboard.save_dashboard(zip_dashboard=True)

# # Load an existing dashboard

import olliepy

dashboard = olliepy.load_interactive_dashboard(dashboard_path='./SALES_DASHBOARD')

# ## Copy charts and number displays from an existing dashboard to a new one

dashboard_v2 = InteractiveDashboard(title='Sales dashboard V2',
                                output_directory='.',
                                dashboard_folder_name='SALES_DASHBOARD_V2',
                                dataframes=[df.sample(300)],
                                dataframes_names=['Sales'],
                                numerical_columns=numerical_columns,
                                categorical_columns=categorical_columns,
                                date_columns=date_columns,
                                generate_encryption_secret=False)

dashboard_v2.bin_numerical_feature('number_of_sales', 'number_of_sales_binned', 10, 'n_sales')
dashboard_v2.bin_numerical_feature('distance_travelled_in_KM', 'distance_binned', 10, 'distance')

dashboard_v2.update_charts(dashboard.get_charts(), keep_existing=False)

dashboard_v2.update_number_displays(dashboard.get_number_displays(), keep_existing=False)

dashboard_v2.create_dashboard(auto_generate_distribution_plots=False)

dashboard_v2.serve_dashboard_from_local_server(mode='server', load_existing_dashboard=False)

StarcoderdataJupyterScriptsDedupFiltered