Real-World Data Science Tasks in Python With Pandas and Plotly
A data analyst brief worked end to end in a Jupyter notebook: load the company data with pandas, explore it with profiling tools, answer specific questions, and present the findings as Plotly charts. It starts from a virtual environment so the project stays reproducible.
Update (November 2026): pandas-profiling is now fg-data-profiling. Install it with pip install fg-data-profiling and import from data_profiling import ProfileReport instead of the pandas_profiling line below. The project files pin Python 3.8 and 2021 package versions; on a current Python, install the packages without the pins.
Set up the environment
A virtual environment keeps the package versions of one project apart from the others. It is optional but recommended. With conda, create and activate one like this:
conda create -n data_analysis python=3.8
conda activate data_analysis
The environment name then shows in your terminal. Install the libraries from the project’s requirements.txt; this can take a while:
pip install -r requirements.txt
If conda is new to you, start with installing Miniconda and setting up virtual environments.
Load the data
Launch Jupyter Notebook in the project folder. The data folder holds the Excel workbook to analyze, and the empty output folder is where the manipulated datasets and charts go. Start with the imports:
import pandas as pd
import plotly
import plotly.express as px
from pandas_profiling import ProfileReport
from autoviz.AutoViz_Class import AutoViz_Class
Set one Plotly template for all charts. I prefer the white one:
template_style = 'plotly_white'
Load the Excel data into a DataFrame and print the first five rows to see the structure:
df = pd.read_excel('data/data.xlsx')
df.head()
Explore the dataset
Before using automated tools, check the basics with df.info(). It shows the number of entries, the column names, the data types and the null values.
df.info()
The profiling report then gives per-column detail such as distinct values and descriptive statistics:
profile = ProfileReport(df)
profile.to_widgets()

AutoViz draws automatic charts for the dataset, such as pair-wise scatter plots:
AV = AutoViz_Class()
df_autoviz = AV.AutoViz('data/data.xlsx')

The same kind of report in three lines is in an exploratory data analysis report in three lines of Python.
Answer questions with pandas
A brief usually comes as concrete questions. Two examples: the highest single sales value, and the average discount for chairs, which needs a filter on the sub-category.
highest_sales = df['Sales'].max()
average_discount = df[df['Sub-Category'] == 'Chairs']['Discount'].mean()
Histogram and box plot
A histogram shows how the sales values are distributed, and a box plot shows the same spread as quartiles and outliers.
fig = px.histogram(df, x='Sales', template=template_style)
fig.show()

fig = px.box(df, y='Sales', template=template_style)
fig.show()

Bar charts by sub-category
To compare sales across sub-categories, group the data first and plot the totals:
sales_by_subcategory = df.groupby('Sub-Category')['Sales'].sum().reset_index()
fig = px.bar(sales_by_subcategory, x='Sub-Category', y='Sales', template=template_style)
fig.show()

The same pattern with the mean of the discount shows where discounts are highest:
average_discount = df.groupby('Sub-Category')['Discount'].mean().reset_index()
fig = px.bar(average_discount, x='Sub-Category', y='Discount', template=template_style)
fig.show()

Scatter plot
A scatter plot of sales against profit, colored by discount, shows how discounts relate to the other two.
fig = px.scatter(df, x='Sales', y='Profit', color='Discount', template=template_style)
fig.show()

Cumulative line chart
To see how sales and profit develop over time, sort by order date and plot the running totals.
df = df.sort_values('Order Date')
df['Cumulative Sales'] = df['Sales'].cumsum()
df['Cumulative Profit'] = df['Profit'].cumsum()
fig = px.line(df, x='Order Date', y=['Cumulative Sales', 'Cumulative Profit'], template=template_style)
fig.show()

For a second walkthrough on a different dataset, see my complete pandas tutorial. To get the charts looking finished, use these Plotly Express fixes.
