liveBook · Manning

Descriptive statistics

As explained in Starting Data Analytics with Generative AI and Python

Descriptive analytics is the examination and summarization of observed data to characterize its distributions, patterns, and relationships.

Descriptive statistics summarize observed data so you can see distributions, patterns, relationships, and possible anomalies. For a restaurant, comparing orders by item, location, and time of day can inform stock, staffing, and promotions. The summaries provide a starting point for decisions and further analysis, not automatic answers about what caused a pattern. section 3.3

A practical descriptive analysis moves from a question to a summary you can inspect:

  • Choose a business question, such as how order statuses vary by product category or seller. section 3.3.4
  • Inspect the data’s rows, dimensions, types, and missing values. In pandas, head(), shape, info(), and isna().sum() help reveal what needs attention before analysis. section 2.3
  • Summarize numerical variables with measures such as the mean, median, standard deviation, and percentiles; count categorical values and compare groups. section 2.3 section 3.3
  • Use charts to make patterns easier to see. Bar charts, histograms, and scatter plots serve different comparisons; cross-tabulations can compare categories. section 3.2 section 3.3

Investigating order statuses

Suppose an e-commerce shop wants to find potential delivery problems. Merge order, item, and product data, then group the records by order status, product category, and seller. A result showing approved orders that apparently never shipped is a lead for further investigation, not a conclusion about why they did not ship. section 3.3.4

import pandas as pd
import matplotlib.pyplot as plt

# Pivot the DataFrame for the stacked bar chart
status_pivot = 
status_distribution_sorted.pivot_table(
index='product_category_name_english',
    columns='order_status',
    values='count',
    aggfunc='sum',
    fill_value=0)

# Plot the stacked bar chart
plt.figure(figsize=(20, 10))
status_pivot.plot(kind='bar', stacked=True, figsize=(20, 10))

plt.xticks(rotation=90, fontsize=10)
plt.yticks(fontsize=12)
plt.xlabel('Product Category', fontsize=12)
plt.ylabel('Count of Orders', fontsize=12)
plt.title('Order Status Distribution by Product Category', fontsize=14)
plt.legend(title='Order Status', title_fontsize=12, fontsize=10, 
loc='upper right')

plt.tight_layout()
plt.show()

This pandas and Matplotlib workflow pivots grouped status counts into a stacked bar chart, making product-category comparisons easier to inspect. section 3.3.4

An AI assistant can suggest research questions, summaries, code, and visualizations, but its suggestions still need judgment. Inspect the data and results, check whether the proposed steps fit the question, and investigate unexpected findings. Some suggested inspection steps may be redundant; choose them for clarity as well as efficiency. section 2.3 section 3.1 section 3.3.4

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Develops an analysis workflow from data inspection and summaries to group comparisons and visualizations, with regression deferred to further analysis.
Examples
Uses restaurant orders and e-commerce order statuses to illustrate operational questions and grouped comparisons.
What you can do after
Apply it via pandas to inspect data, summarize variables, compare groups, and prepare visualizations.
How it connects
Connects descriptive statistics to data quality, visualization, cross-tabulation, regression, and predictive analytics.

Also explained in

Compare how 6 books explain descriptive statistics →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.