<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Samuel Mwai</title>
    <description>The latest articles on DEV Community by Samuel Mwai (@samuel_mwai).</description>
    <link>https://dev.to/samuel_mwai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3918459%2F4d8c685d-0760-49fb-999c-f7c6ac75345b.png</url>
      <title>DEV Community: Samuel Mwai</title>
      <link>https://dev.to/samuel_mwai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samuel_mwai"/>
    <language>en</language>
    <item>
      <title>Unsupervised Learning: Key Concepts and Techniques</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Mon, 24 Aug 2026 07:07:38 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/unsupervised-learning-key-concepts-and-techniques-15jk</link>
      <guid>https://dev.to/samuel_mwai/unsupervised-learning-key-concepts-and-techniques-15jk</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Unsupervised Learning is a branch of Machine Learning where a computer learns patterns and relationships from data without being given predefined labels or answers. Unlike supervised learning, where a model is trained using input data and known target values, unsupervised learning works mainly with &lt;strong&gt;unlabelled data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The main goal is to discover hidden patterns, groups, structures, or relationships within a dataset. Unsupervised learning is widely used in areas such as customer segmentation, fraud detection, recommendation systems, image analysis, and data exploration.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Unsupervised Learning?
&lt;/h2&gt;

&lt;p&gt;In unsupervised learning, the dataset contains input features but does not contain a target variable that tells the model the correct answer.&lt;/p&gt;

&lt;p&gt;For example, a business may have customer information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Age&lt;/li&gt;
&lt;li&gt;Income&lt;/li&gt;
&lt;li&gt;Number of purchases&lt;/li&gt;
&lt;li&gt;Amount spent&lt;/li&gt;
&lt;li&gt;Location&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of telling the model which customers belong to which group, an unsupervised learning algorithm can analyse the data and discover groups of customers with similar characteristics.&lt;/p&gt;

&lt;p&gt;This makes unsupervised learning particularly useful when labelled data is unavailable or expensive to obtain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Techniques in Unsupervised Learning
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Clustering
&lt;/h3&gt;

&lt;p&gt;Clustering is one of the most common unsupervised learning techniques. It involves grouping similar observations together while keeping dissimilar observations in different groups.&lt;/p&gt;

&lt;p&gt;One popular clustering algorithm is &lt;strong&gt;K-Means Clustering&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;K-Means works by:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Choosing the number of clusters, represented by &lt;strong&gt;K&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Randomly selecting initial cluster centres.&lt;/li&gt;
&lt;li&gt;Assigning each data point to the nearest centre.&lt;/li&gt;
&lt;li&gt;Calculating new cluster centres.&lt;/li&gt;
&lt;li&gt;Repeating the process until the clusters become stable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, K-Means can be used by a company to divide customers into groups such as low-value, medium-value, and high-value customers.&lt;/p&gt;

&lt;p&gt;A common method for choosing the value of K is the &lt;strong&gt;Elbow Method&lt;/strong&gt;, which compares the number of clusters with the within-cluster variation, commonly measured using inertia.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Hierarchical Clustering
&lt;/h3&gt;

&lt;p&gt;Hierarchical clustering creates a hierarchy of groups rather than requiring the number of clusters to be selected at the beginning.&lt;/p&gt;

&lt;p&gt;There are two main approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Agglomerative clustering&lt;/strong&gt; – starts with individual data points and gradually combines similar groups.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Divisive clustering&lt;/strong&gt; – starts with one large group and repeatedly divides it into smaller groups.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The results can be represented using a &lt;strong&gt;dendrogram&lt;/strong&gt;, which is a tree-like diagram showing how observations or clusters are combined.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Dimensionality Reduction
&lt;/h3&gt;

&lt;p&gt;Datasets can contain many features, making them difficult to analyse and visualise. Dimensionality reduction reduces the number of features while attempting to preserve important information.&lt;/p&gt;

&lt;p&gt;One important technique is &lt;strong&gt;Principal Component Analysis (PCA)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;PCA transforms the original variables into a smaller number of new variables called &lt;strong&gt;principal components&lt;/strong&gt;. The first principal component captures the greatest amount of variation in the data, followed by the second component, and so on.&lt;/p&gt;

&lt;p&gt;PCA can be useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reducing the complexity of datasets&lt;/li&gt;
&lt;li&gt;Visualising high-dimensional data&lt;/li&gt;
&lt;li&gt;Removing redundant information&lt;/li&gt;
&lt;li&gt;Improving computational efficiency&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Association Rule Learning
&lt;/h3&gt;

&lt;p&gt;Association rule learning is used to discover relationships between items or events.&lt;/p&gt;

&lt;p&gt;A common example is &lt;strong&gt;market basket analysis&lt;/strong&gt;. A supermarket can analyse customer transactions to discover that customers who purchase one product are also likely to purchase another.&lt;/p&gt;

&lt;p&gt;Important concepts include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Support&lt;/strong&gt; – how frequently an item or combination appears in the dataset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confidence&lt;/strong&gt; – how often one item is purchased when another item is purchased.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lift&lt;/strong&gt; – measures how strongly two items are associated compared with what would be expected by chance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Algorithms such as &lt;strong&gt;Apriori&lt;/strong&gt; and &lt;strong&gt;FP-Growth&lt;/strong&gt; can be used for association rule mining.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Anomaly Detection
&lt;/h3&gt;

&lt;p&gt;Unsupervised learning can also be used to identify unusual observations known as &lt;strong&gt;anomalies or outliers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, a bank may analyse transaction data and identify transactions that are significantly different from normal customer behaviour.&lt;/p&gt;

&lt;p&gt;Techniques such as &lt;strong&gt;Isolation Forest&lt;/strong&gt;, clustering, and statistical methods can be used for anomaly detection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Preparation for Unsupervised Learning
&lt;/h2&gt;

&lt;p&gt;Data preparation is an important part of unsupervised learning because poor-quality data can produce misleading patterns.&lt;/p&gt;

&lt;p&gt;Common preprocessing steps include:&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling Missing Values
&lt;/h3&gt;

&lt;p&gt;Missing values may need to be removed or replaced using appropriate methods such as the mean, median, or a meaningful category such as "Unknown."&lt;/p&gt;

&lt;h3&gt;
  
  
  Encoding Categorical Variables
&lt;/h3&gt;

&lt;p&gt;Machine learning algorithms generally require numerical input. Categorical variables such as gender, country, or education level may therefore need to be converted into numerical representations using techniques such as &lt;strong&gt;One-Hot Encoding&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Feature Scaling
&lt;/h3&gt;

&lt;p&gt;Scaling is especially important for distance-based algorithms such as K-Means.&lt;/p&gt;

&lt;p&gt;For example, if one feature ranges from 0–100 and another ranges from 0–1, the larger feature may have a greater influence on the distance calculation.&lt;/p&gt;

&lt;p&gt;Common scaling techniques include &lt;strong&gt;StandardScaler&lt;/strong&gt; and &lt;strong&gt;MinMaxScaler&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluating Unsupervised Learning Models
&lt;/h2&gt;

&lt;p&gt;Evaluating unsupervised learning can be more difficult than evaluating supervised learning because there may be no known correct labels.&lt;/p&gt;

&lt;p&gt;For clustering, common evaluation methods include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Silhouette Score&lt;/strong&gt; – measures how similar an observation is to its own cluster compared with other clusters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inertia&lt;/strong&gt; – measures the distance between observations and their cluster centres.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Davies-Bouldin Index&lt;/strong&gt; – evaluates the separation and compactness of clusters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Visualisation is also an important part of evaluation. Scatter plots and dimensionality reduction techniques such as PCA can help us understand whether discovered groups make sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applications of Unsupervised Learning
&lt;/h2&gt;

&lt;p&gt;Unsupervised learning has many real-world applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customer segmentation:&lt;/strong&gt; Businesses can group customers according to purchasing behaviour and preferences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fraud detection:&lt;/strong&gt; Unusual transactions can be identified as potential fraudulent activities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommendation systems:&lt;/strong&gt; Patterns in user behaviour can be used to recommend products, movies, or other content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Healthcare:&lt;/strong&gt; Patient data can be grouped according to similar characteristics or conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marketing:&lt;/strong&gt; Companies can discover groups of customers with similar interests and behaviours.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data exploration:&lt;/strong&gt; Analysts can use unsupervised learning to discover patterns before building predictive models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages and Limitations
&lt;/h2&gt;

&lt;p&gt;One major advantage of unsupervised learning is that it does not require labelled data. This makes it useful when obtaining labels is difficult or expensive. It can also reveal patterns that were not previously known.&lt;/p&gt;

&lt;p&gt;However, unsupervised learning also has limitations. The patterns discovered by an algorithm may not always have a clear real-world meaning. Choosing the appropriate algorithm and parameters can also be challenging. In addition, evaluating the quality of the results can be difficult because there may be no predefined correct answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Unsupervised learning is an important area of Machine Learning that focuses on discovering hidden patterns and structures in unlabelled data. Key techniques include &lt;strong&gt;K-Means clustering, hierarchical clustering, PCA, association rule learning, and anomaly detection&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Successful unsupervised learning requires proper data preprocessing, appropriate algorithm selection, and careful evaluation of the discovered patterns. As organisations continue to collect large amounts of data, unsupervised learning provides valuable tools for exploring that data and discovering insights that may not be immediately visible.&lt;/p&gt;

&lt;p&gt;Understanding these concepts provides a strong foundation for more advanced Machine Learning and Data Science applications.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Star vs. Snowflake Schema: Choosing Your Data Warehouse Schema</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Wed, 19 Aug 2026 06:56:00 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/star-vs-snowflake-schema-choosing-your-data-warehouse-schema-1kad</link>
      <guid>https://dev.to/samuel_mwai/star-vs-snowflake-schema-choosing-your-data-warehouse-schema-1kad</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A data warehouse is designed to store and organize large amounts of data so that organizations can efficiently perform analysis, reporting, business intelligence, and decision-making.&lt;/p&gt;

&lt;p&gt;One of the most important decisions when designing a data warehouse is choosing the right schema.&lt;/p&gt;

&lt;p&gt;Two of the most common approaches are the:&lt;/p&gt;

&lt;p&gt;⭐ Star Schema&lt;br&gt;
❄️ Snowflake Schema&lt;/p&gt;

&lt;p&gt;Both organize data using fact tables and dimension tables, but they differ in how those dimensions are structured.&lt;/p&gt;

&lt;p&gt;Choosing between them can affect:&lt;/p&gt;

&lt;p&gt;Query performance&lt;br&gt;
Storage requirements&lt;br&gt;
Data complexity&lt;br&gt;
Ease of reporting&lt;br&gt;
Maintenance&lt;br&gt;
Scalability&lt;br&gt;
BI tools such as Power BI&lt;/p&gt;

&lt;p&gt;This article explains both schemas, compares their advantages and disadvantages, and provides a practical guide for choosing the right one.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What Is a Data Warehouse Schema?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A schema is the structure used to organize tables and relationships inside a data warehouse.&lt;/p&gt;

&lt;p&gt;For example, imagine a company wants to analyze its sales.&lt;/p&gt;

&lt;p&gt;The company might have information about:&lt;/p&gt;

&lt;p&gt;Customers&lt;br&gt;
Products&lt;br&gt;
Stores&lt;br&gt;
Dates&lt;br&gt;
Sales transactions&lt;/p&gt;

&lt;p&gt;Instead of putting everything into one huge table, a data warehouse separates the information into related tables.&lt;/p&gt;

&lt;p&gt;A typical design looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                DATA WAREHOUSE
                      │
         ┌────────────┴────────────┐
         │                         │
    FACT TABLES              DIMENSION TABLES
         │                         │
   Sales transactions       Customers
   Orders                   Products
   Payments                 Stores
                            Dates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The two major schema designs discussed in this article organize these tables differently.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fact Tables vs. Dimension Tables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before understanding star and snowflake schemas, you need to understand two important types of tables.&lt;/p&gt;

&lt;p&gt;Fact Tables&lt;/p&gt;

&lt;p&gt;A fact table contains measurable business events.&lt;/p&gt;

&lt;p&gt;For a sales warehouse, a fact table might contain:&lt;/p&gt;

&lt;p&gt;sale_id customer_id product_id  date_id quantity    sales_amount&lt;br&gt;
1001    25  101 20260101    2   5000&lt;br&gt;
1002    31  105 20260102    1   3000&lt;br&gt;
1003    25  102 20260103    4   8000&lt;/p&gt;

&lt;p&gt;The fact table typically contains:&lt;/p&gt;

&lt;p&gt;Foreign keys&lt;br&gt;
Numeric measurements&lt;br&gt;
Business transaction identifiers&lt;/p&gt;

&lt;p&gt;Examples of facts include:&lt;/p&gt;

&lt;p&gt;Sales amount&lt;br&gt;
Quantity sold&lt;br&gt;
Profit&lt;br&gt;
Revenue&lt;br&gt;
Discount&lt;br&gt;
Cost&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dimension Tables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dimension tables provide context about the facts.&lt;/p&gt;

&lt;p&gt;For example, instead of storing the customer's entire information in every sales record, we create a customer dimension.&lt;/p&gt;

&lt;p&gt;Customer Dimension&lt;br&gt;
customer_id customer_name   city    country&lt;br&gt;
25  John    Nairobi Kenya&lt;br&gt;
31  Mary    Mombasa Kenya&lt;br&gt;
42  Peter   Kampala Uganda&lt;/p&gt;

&lt;p&gt;Dimensions answer questions such as:&lt;/p&gt;

&lt;p&gt;Who?&lt;br&gt;
What?&lt;br&gt;
Where?&lt;br&gt;
When?&lt;br&gt;
Which category?&lt;/p&gt;

&lt;p&gt;Common dimensions include:&lt;/p&gt;

&lt;p&gt;Customer&lt;br&gt;
Product&lt;br&gt;
Date&lt;br&gt;
Location&lt;br&gt;
Employee&lt;br&gt;
Store&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Star Schema ⭐&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A star schema is a data warehouse design where a central fact table connects directly to several dimension tables.&lt;/p&gt;

&lt;p&gt;It is called a star schema because the structure resembles a star.&lt;/p&gt;

&lt;p&gt;5&lt;/p&gt;

&lt;p&gt;The basic structure looks like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   Date
                    │
                    │
                    ▼
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Customer ─────────► SALES ◄───────── Product&lt;br&gt;
                        │&lt;br&gt;
                        │&lt;br&gt;
                        ▼&lt;br&gt;
                      Store&lt;/p&gt;

&lt;p&gt;The SALES table is the central fact table.&lt;/p&gt;

&lt;p&gt;The dimensions surround it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Example of a Star Schema&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Imagine an online retailer.&lt;/p&gt;

&lt;p&gt;The fact table could be:&lt;/p&gt;

&lt;p&gt;Fact_Sales&lt;br&gt;
sale_id customer_id product_id  date_id store_id    quantity    revenue&lt;br&gt;
1   101 501 20260101    10  2   5000&lt;br&gt;
2   102 502 20260101    11  1   3000&lt;br&gt;
3   101 503 20260102    10  3   9000&lt;/p&gt;

&lt;p&gt;It could connect directly to:&lt;/p&gt;

&lt;p&gt;Dim_Customer&lt;br&gt;
customer_id customer_name   city    country&lt;br&gt;
101 John    Nairobi Kenya&lt;br&gt;
102 Mary    Mombasa Kenya&lt;br&gt;
Dim_Product&lt;br&gt;
product_id  product_name    category    brand&lt;br&gt;
501 Laptop  Electronics Brand A&lt;br&gt;
502 Phone   Electronics Brand B&lt;br&gt;
503 Headphones  Accessories Brand C&lt;br&gt;
Dim_Date&lt;br&gt;
date_id date    month   quarter year&lt;br&gt;
20260101    2026-01-01  January Q1  2026&lt;br&gt;
20260102    2026-01-02  January Q1  2026&lt;/p&gt;

&lt;p&gt;The important point is that the dimensions are relatively denormalized.&lt;/p&gt;

&lt;p&gt;For example, the product category and brand can exist directly inside Dim_Product.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Advantages of Star Schema
6.1 Simple to Understand&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Star schemas are relatively easy for analysts and BI developers to understand.&lt;/p&gt;

&lt;p&gt;The structure is straightforward:&lt;/p&gt;

&lt;p&gt;Dimensions → Fact Table&lt;/p&gt;

&lt;p&gt;This makes it particularly suitable for reporting environments.&lt;/p&gt;

&lt;p&gt;6.2 Fast Queries&lt;/p&gt;

&lt;p&gt;Star schemas can provide efficient analytical queries because users often need only a small number of joins.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;SELECT&lt;br&gt;
    p.category,&lt;br&gt;
    SUM(f.revenue) AS total_revenue&lt;br&gt;
FROM fact_sales f&lt;br&gt;
JOIN dim_product p&lt;br&gt;
    ON f.product_id = p.product_id&lt;br&gt;
GROUP BY p.category;&lt;/p&gt;

&lt;p&gt;The query only needs to join the fact table with the relevant dimension.&lt;/p&gt;

&lt;p&gt;6.3 Good for BI Tools&lt;/p&gt;

&lt;p&gt;Star schemas work particularly well with business intelligence tools such as:&lt;/p&gt;

&lt;p&gt;Power BI&lt;br&gt;
Tableau&lt;br&gt;
Looker&lt;br&gt;
Qlik&lt;/p&gt;

&lt;p&gt;In Power BI, a clean star schema often makes the model easier to understand and helps create reliable relationships and measures.&lt;/p&gt;

&lt;p&gt;6.4 Easier Reporting&lt;/p&gt;

&lt;p&gt;Analysts can easily answer questions such as:&lt;/p&gt;

&lt;p&gt;What were sales by country?&lt;/p&gt;

&lt;p&gt;What was revenue by product category?&lt;/p&gt;

&lt;p&gt;Which store generated the most sales?&lt;/p&gt;

&lt;p&gt;The dimensions provide the descriptive information while the fact table provides the measurements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Disadvantages of Star Schema&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Despite its advantages, star schema has some limitations.&lt;/p&gt;

&lt;p&gt;Data Duplication&lt;/p&gt;

&lt;p&gt;Because dimensions are often denormalized, some information may be repeated.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;product category    department&lt;br&gt;
Laptop  Electronics Technology&lt;br&gt;
Phone   Electronics Technology&lt;br&gt;
Monitor Electronics Technology&lt;/p&gt;

&lt;p&gt;The category and department values are repeated.&lt;/p&gt;

&lt;p&gt;Larger Dimension Tables&lt;/p&gt;

&lt;p&gt;Denormalization can increase the amount of storage required.&lt;/p&gt;

&lt;p&gt;Updating Data&lt;/p&gt;

&lt;p&gt;If a value is duplicated across many records, maintaining consistency can become more difficult in certain designs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Snowflake Schema ❄️&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A snowflake schema is similar to a star schema, but dimension tables are further normalized into multiple related tables.&lt;/p&gt;

&lt;p&gt;5&lt;/p&gt;

&lt;p&gt;Instead of having one large product dimension:&lt;/p&gt;

&lt;p&gt;Dim_Product&lt;br&gt;
    │&lt;br&gt;
    ├── Product&lt;br&gt;
    ├── Category&lt;br&gt;
    └── Department&lt;/p&gt;

&lt;p&gt;we separate the information:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Dim_Department
                   │
                   ▼
              Dim_Category
                   │
                   ▼
              Dim_Product
                   │
                   ▼
               Fact_Sales
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The resulting structure looks more complex, which is why it resembles a snowflake.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Example of a Snowflake Schema&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;p&gt;Dim_Product&lt;br&gt;
product_id  product_name    category    department&lt;br&gt;
501 Laptop  Electronics Technology&lt;br&gt;
502 Phone   Electronics Technology&lt;br&gt;
503 Desk    Furniture   Home&lt;/p&gt;

&lt;p&gt;we could normalize the structure.&lt;/p&gt;

&lt;p&gt;Dim_Product&lt;br&gt;
product_id  product_name    category_id&lt;br&gt;
501 Laptop  10&lt;br&gt;
502 Phone   10&lt;br&gt;
503 Desk    20&lt;br&gt;
Dim_Category&lt;br&gt;
category_id category_name   department_id&lt;br&gt;
10  Electronics 1&lt;br&gt;
20  Furniture   2&lt;br&gt;
Dim_Department&lt;br&gt;
department_id   department_name&lt;br&gt;
1   Technology&lt;br&gt;
2   Home&lt;/p&gt;

&lt;p&gt;Now the information is divided among several related tables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why Normalize a Data Warehouse?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Normalization reduces unnecessary duplication.&lt;/p&gt;

&lt;p&gt;Consider a product dimension with thousands of products.&lt;/p&gt;

&lt;p&gt;If every product stores:&lt;/p&gt;

&lt;p&gt;Product&lt;br&gt;
Category&lt;br&gt;
Department&lt;br&gt;
Division&lt;/p&gt;

&lt;p&gt;the same category and department information may appear many times.&lt;/p&gt;

&lt;p&gt;A snowflake schema can store those attributes separately.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;10, Electronics, Technology&lt;/p&gt;

&lt;p&gt;can exist once in the category table instead of being repeated across many product records.&lt;/p&gt;

&lt;p&gt;This can improve:&lt;/p&gt;

&lt;p&gt;Data consistency&lt;br&gt;
Storage efficiency&lt;br&gt;
Maintenance&lt;/p&gt;

&lt;p&gt;However, normalization also introduces additional joins.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Advantages of Snowflake Schema
11.1 Reduced Data Redundancy&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because dimensions are normalized, repeated information can be reduced.&lt;/p&gt;

&lt;p&gt;11.2 Better Data Consistency&lt;/p&gt;

&lt;p&gt;If a department name changes, the change can be made in one location.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Technology&lt;/p&gt;

&lt;p&gt;could be changed centrally rather than updating many product records.&lt;/p&gt;

&lt;p&gt;11.3 More Structured Data&lt;/p&gt;

&lt;p&gt;Snowflake schemas can be useful when dimensions have complex hierarchies.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Country&lt;br&gt;
   ↓&lt;br&gt;
Region&lt;br&gt;
   ↓&lt;br&gt;
City&lt;br&gt;
   ↓&lt;br&gt;
Store&lt;/p&gt;

&lt;p&gt;or:&lt;/p&gt;

&lt;p&gt;Department&lt;br&gt;
   ↓&lt;br&gt;
Category&lt;br&gt;
   ↓&lt;br&gt;
Subcategory&lt;br&gt;
   ↓&lt;br&gt;
Product&lt;/p&gt;

&lt;p&gt;These relationships can be represented naturally using normalized tables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Disadvantages of Snowflake Schema&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main disadvantage is complexity.&lt;/p&gt;

&lt;p&gt;A query that could require one join in a star schema might require several joins in a snowflake schema.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;SELECT&lt;br&gt;
    d.department_name,&lt;br&gt;
    SUM(f.revenue)&lt;br&gt;
FROM fact_sales f&lt;br&gt;
JOIN dim_product p&lt;br&gt;
    ON f.product_id = p.product_id&lt;br&gt;
JOIN dim_category c&lt;br&gt;
    ON p.category_id = c.category_id&lt;br&gt;
JOIN dim_department d&lt;br&gt;
    ON c.department_id = d.department_id&lt;br&gt;
GROUP BY d.department_name;&lt;/p&gt;

&lt;p&gt;Compare this with a star schema:&lt;/p&gt;

&lt;p&gt;SELECT&lt;br&gt;
    p.department_name,&lt;br&gt;
    SUM(f.revenue)&lt;br&gt;
FROM fact_sales f&lt;br&gt;
JOIN dim_product p&lt;br&gt;
    ON f.product_id = p.product_id&lt;br&gt;
GROUP BY p.department_name;&lt;/p&gt;

&lt;p&gt;The star schema is simpler.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Star vs Snowflake&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The fundamental difference can be summarized as:&lt;/p&gt;

&lt;p&gt;STAR SCHEMA&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          Customer
             │
             │
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Product ───── Fact ───── Date&lt;br&gt;
                 │&lt;br&gt;
                 │&lt;br&gt;
               Store&lt;/p&gt;

&lt;p&gt;versus:&lt;/p&gt;

&lt;p&gt;SNOWFLAKE SCHEMA&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Department
                  │
               Category
                  │
               Product
                  │
                  ▼
               FACT
             /      \
         Customer    Date
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The star schema keeps dimensions closer to the fact table.&lt;/p&gt;

&lt;p&gt;The snowflake schema breaks dimensions into additional normalized tables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Star vs Snowflake: Comparison
Feature Star Schema ⭐ Snowflake Schema ❄️
Structure   Simple  More complex
Dimensions  Denormalized    Normalized
Number of tables    Usually fewer   Usually more
Joins   Fewer   More
Query simplicity    High    Lower
Storage redundancy  Higher  Lower
Maintenance Simple  More structured
BI friendliness Excellent   Good
Reporting   Very good   Good
Complex hierarchies Less natural    Very good
Learning curve  Easier  Higher&lt;/li&gt;
&lt;li&gt;Which One Is Faster?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is no universal answer.&lt;/p&gt;

&lt;p&gt;Performance depends on:&lt;/p&gt;

&lt;p&gt;Database engine&lt;br&gt;
Data size&lt;br&gt;
Indexing&lt;br&gt;
Partitioning&lt;br&gt;
Query design&lt;br&gt;
Columnar storage&lt;br&gt;
Caching&lt;br&gt;
Materialized views&lt;br&gt;
Query optimizer&lt;/p&gt;

&lt;p&gt;However, star schemas often have an advantage for analytical workloads because queries can require fewer joins.&lt;/p&gt;

&lt;p&gt;Snowflake schemas may require more joins because dimensions are normalized.&lt;/p&gt;

&lt;p&gt;Modern cloud data warehouses can optimize many of these operations effectively, so schema choice should not be based purely on theoretical join counts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Star Schema in Power BI&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Star schemas are particularly useful when creating a Power BI semantic model.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            Dim_Date
                │
                │
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Dim_Customer ─── Fact_Sales ─── Dim_Product&lt;br&gt;
                    │&lt;br&gt;
                    │&lt;br&gt;
                Dim_Store&lt;/p&gt;

&lt;p&gt;The fact table sits in the center.&lt;/p&gt;

&lt;p&gt;Dimensions filter the fact table.&lt;/p&gt;

&lt;p&gt;This creates a clean model for measures such as:&lt;/p&gt;

&lt;p&gt;Total Sales =&lt;br&gt;
SUM(Fact_Sales[SalesAmount])&lt;/p&gt;

&lt;p&gt;You can then analyze total sales by:&lt;/p&gt;

&lt;p&gt;Year&lt;br&gt;
Month&lt;br&gt;
Customer&lt;br&gt;
Product&lt;br&gt;
Category&lt;br&gt;
Store&lt;br&gt;
Country&lt;/p&gt;

&lt;p&gt;without putting everything into one massive table.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why Star Schema Is Popular in Power BI&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Power BI works particularly well with a model where:&lt;/p&gt;

&lt;p&gt;Dimension → Fact&lt;/p&gt;

&lt;p&gt;relationships are clear.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Dim_Product[ProductID]&lt;br&gt;
          │&lt;br&gt;
          │ 1&lt;br&gt;
          ▼&lt;br&gt;
Fact_Sales[ProductID]&lt;br&gt;
          *&lt;/p&gt;

&lt;p&gt;This represents a one-to-many relationship.&lt;/p&gt;

&lt;p&gt;One product can appear in many sales transactions.&lt;/p&gt;

&lt;p&gt;Similarly:&lt;/p&gt;

&lt;p&gt;Dim_Customer&lt;br&gt;
      1&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Fact_Sales&lt;br&gt;
      *&lt;/p&gt;

&lt;p&gt;One customer can have many sales.&lt;/p&gt;

&lt;p&gt;This design makes filtering and DAX calculations much easier to manage.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When Should You Choose a Star Schema?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A star schema is usually a strong choice when:&lt;/p&gt;

&lt;p&gt;You prioritize simplicity&lt;/p&gt;

&lt;p&gt;Your analysts should be able to understand the model quickly.&lt;/p&gt;

&lt;p&gt;You are building BI dashboards&lt;/p&gt;

&lt;p&gt;Especially when using tools such as Power BI or Tableau.&lt;/p&gt;

&lt;p&gt;You have straightforward dimensions&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Customer&lt;br&gt;
Product&lt;br&gt;
Date&lt;br&gt;
Store&lt;br&gt;
You want simple queries&lt;/p&gt;

&lt;p&gt;Fewer joins can make analytical SQL easier to write and maintain.&lt;/p&gt;

&lt;p&gt;You want a semantic model&lt;/p&gt;

&lt;p&gt;Star schemas are particularly effective for business reporting.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When Should You Choose a Snowflake Schema?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A snowflake schema may be appropriate when:&lt;/p&gt;

&lt;p&gt;Dimensions have complex hierarchies&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Country&lt;br&gt;
   ↓&lt;br&gt;
Region&lt;br&gt;
   ↓&lt;br&gt;
City&lt;br&gt;
   ↓&lt;br&gt;
Store&lt;br&gt;
Reducing redundancy is important&lt;/p&gt;

&lt;p&gt;Normalization can reduce repeated dimension information.&lt;/p&gt;

&lt;p&gt;Dimensions are very large&lt;/p&gt;

&lt;p&gt;Breaking them into smaller related tables may provide organizational or storage benefits depending on the platform.&lt;/p&gt;

&lt;p&gt;Data governance is important&lt;/p&gt;

&lt;p&gt;Centralizing shared attributes can make some updates and consistency rules easier to manage.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Can You Use Both?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;Real-world data warehouses do not always have to be purely star or purely snowflake.&lt;/p&gt;

&lt;p&gt;A model can contain mostly denormalized dimensions while selectively normalizing particularly complex parts.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Dim_Date
                │
                ▼
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Customer ─────── Fact_Sales ───── Product&lt;br&gt;
                                      │&lt;br&gt;
                                      ▼&lt;br&gt;
                                  Category&lt;br&gt;
                                      │&lt;br&gt;
                                      ▼&lt;br&gt;
                                  Department&lt;/p&gt;

&lt;p&gt;This is sometimes described as a hybrid approach.&lt;/p&gt;

&lt;p&gt;The goal is not to follow a schema design purely because it has a particular name.&lt;/p&gt;

&lt;p&gt;The goal is to create a model that balances:&lt;/p&gt;

&lt;p&gt;Performance + simplicity + maintainability + business requirements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Practical Decision Framework&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When deciding between star and snowflake schemas, ask the following questions.&lt;/p&gt;

&lt;p&gt;Question 1: Who will use the data?&lt;/p&gt;

&lt;p&gt;If the primary users are:&lt;/p&gt;

&lt;p&gt;Business analysts&lt;br&gt;
BI developers&lt;br&gt;
Power BI users&lt;/p&gt;

&lt;p&gt;a star schema is often easier.&lt;/p&gt;

&lt;p&gt;Question 2: How complex are the dimensions?&lt;/p&gt;

&lt;p&gt;Simple dimensions:&lt;/p&gt;

&lt;p&gt;Customer&lt;br&gt;
Product&lt;br&gt;
Date&lt;/p&gt;

&lt;p&gt;→ Star schema is usually a good fit.&lt;/p&gt;

&lt;p&gt;Complex hierarchies:&lt;/p&gt;

&lt;p&gt;Division&lt;br&gt;
 ↓&lt;br&gt;
Department&lt;br&gt;
 ↓&lt;br&gt;
Category&lt;br&gt;
 ↓&lt;br&gt;
Subcategory&lt;br&gt;
 ↓&lt;br&gt;
Product&lt;/p&gt;

&lt;p&gt;→ Snowflake or a hybrid approach may make sense.&lt;/p&gt;

&lt;p&gt;Question 3: How important is simplicity?&lt;/p&gt;

&lt;p&gt;If your goal is easy reporting and self-service analytics, favor the simpler model.&lt;/p&gt;

&lt;p&gt;Question 4: How much redundancy exists?&lt;/p&gt;

&lt;p&gt;If dimensions contain large amounts of repeated information, normalization may be worth considering.&lt;/p&gt;

&lt;p&gt;Question 5: What does your database platform support?&lt;/p&gt;

&lt;p&gt;Modern data warehouse platforms differ significantly in how they handle joins, storage, compression, and query optimization.&lt;/p&gt;

&lt;p&gt;Always evaluate the design against your actual workload.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Example: E-Commerce Data Warehouse&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Imagine an e-commerce company wants to analyze:&lt;/p&gt;

&lt;p&gt;Revenue&lt;br&gt;
Products&lt;br&gt;
Customers&lt;br&gt;
Stores&lt;br&gt;
Dates&lt;/p&gt;

&lt;p&gt;A star schema could look like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   Dim_Date
                      │
                      │
                      ▼
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Dim_Customer ─────── Fact_Sales ─────── Dim_Product&lt;br&gt;
                          │&lt;br&gt;
                          │&lt;br&gt;
                          ▼&lt;br&gt;
                       Dim_Store&lt;/p&gt;

&lt;p&gt;The fact table contains:&lt;/p&gt;

&lt;p&gt;sale_id&lt;br&gt;
customer_id&lt;br&gt;
product_id&lt;br&gt;
date_id&lt;br&gt;
store_id&lt;br&gt;
quantity&lt;br&gt;
sales_amount&lt;br&gt;
profit&lt;/p&gt;

&lt;p&gt;The dimensions contain descriptive information.&lt;/p&gt;

&lt;p&gt;This would be an excellent starting point for a Power BI sales dashboard.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Example of a More Complex Snowflake&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose the company has a very detailed product hierarchy:&lt;/p&gt;

&lt;p&gt;Department&lt;br&gt;
     │&lt;br&gt;
     ▼&lt;br&gt;
Category&lt;br&gt;
     │&lt;br&gt;
     ▼&lt;br&gt;
Subcategory&lt;br&gt;
     │&lt;br&gt;
     ▼&lt;br&gt;
Product&lt;br&gt;
     │&lt;br&gt;
     ▼&lt;br&gt;
Fact Sales&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Technology&lt;br&gt;
    ↓&lt;br&gt;
Computers&lt;br&gt;
    ↓&lt;br&gt;
Laptops&lt;br&gt;
    ↓&lt;br&gt;
Gaming Laptop&lt;/p&gt;

&lt;p&gt;A snowflake schema can represent this hierarchy without repeating department and category information for every product.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Common Mistakes
Mistake 1: Creating One Giant Table&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Putting every attribute into one table may seem simple at first, but it can lead to:&lt;/p&gt;

&lt;p&gt;Huge tables&lt;br&gt;
Duplicate data&lt;br&gt;
Difficult maintenance&lt;br&gt;
Poor data quality&lt;br&gt;
Complex transformations&lt;br&gt;
Mistake 2: Over-Normalizing&lt;/p&gt;

&lt;p&gt;Normalization can be useful, but creating too many tables can make analytical queries unnecessarily complicated.&lt;/p&gt;

&lt;p&gt;You don't want a simple sales report to require ten joins.&lt;/p&gt;

&lt;p&gt;Mistake 3: Ignoring the Business Question&lt;/p&gt;

&lt;p&gt;Schema design should begin with understanding what the organization wants to analyze.&lt;/p&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;p&gt;What business process are we modeling?&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Sales&lt;br&gt;
Inventory&lt;br&gt;
Marketing&lt;br&gt;
Finance&lt;br&gt;
Customer service&lt;/p&gt;

&lt;p&gt;Then identify the facts and dimensions.&lt;/p&gt;

&lt;p&gt;Mistake 4: Choosing Based Only on Storage&lt;/p&gt;

&lt;p&gt;Storage is important, but it is not the only consideration.&lt;/p&gt;

&lt;p&gt;You should also consider:&lt;/p&gt;

&lt;p&gt;Query performance&lt;br&gt;
User experience&lt;br&gt;
Maintainability&lt;br&gt;
Data governance&lt;br&gt;
BI tools&lt;br&gt;
Complexity&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Simple Rule of Thumb&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are unsure which design to choose:&lt;/p&gt;

&lt;p&gt;Start with a star schema.&lt;/p&gt;

&lt;p&gt;It is generally easier to understand, easier to query, and works very well for analytical reporting and BI.&lt;/p&gt;

&lt;p&gt;Move toward snowflake or a hybrid design when there is a specific reason, such as:&lt;/p&gt;

&lt;p&gt;Complex dimension hierarchies&lt;br&gt;
Significant redundancy&lt;br&gt;
Governance requirements&lt;br&gt;
Very large dimensions&lt;br&gt;
A database architecture that benefits from further normalization&lt;br&gt;
Conclusion&lt;/p&gt;

&lt;p&gt;Star and snowflake schemas are two important approaches to designing analytical data warehouses.&lt;/p&gt;

&lt;p&gt;The star schema keeps a central fact table surrounded by relatively denormalized dimension tables.&lt;/p&gt;

&lt;p&gt;The snowflake schema takes some of those dimensions and normalizes them into additional related tables.&lt;/p&gt;

&lt;p&gt;The key difference is:&lt;/p&gt;

&lt;p&gt;⭐ Star = simpler, more denormalized, fewer joins&lt;/p&gt;

&lt;p&gt;❄️ Snowflake = more normalized, more tables, more joins&lt;/p&gt;

&lt;p&gt;Neither schema is universally better.&lt;/p&gt;

&lt;p&gt;The right choice depends on your:&lt;/p&gt;

&lt;p&gt;Business requirements&lt;br&gt;
Data structure&lt;br&gt;
Query patterns&lt;br&gt;
BI tools&lt;br&gt;
Data volume&lt;br&gt;
Performance requirements&lt;br&gt;
Governance needs&lt;/p&gt;

&lt;p&gt;For many modern analytics and Power BI projects, a well-designed star schema is an excellent default because it provides a balance of simplicity, performance, and usability.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>architecture</category>
      <category>database</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title># Statistics for Data Science</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Wed, 19 Aug 2026 06:51:05 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/-statistics-for-data-science-4mjo</link>
      <guid>https://dev.to/samuel_mwai/-statistics-for-data-science-4mjo</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Statistics is one of the foundations of data science. Data scientists work with large amounts of information, but simply having data is not enough. The real challenge is understanding what the data means, identifying patterns, measuring uncertainty, and using evidence to make reliable decisions.&lt;/p&gt;

&lt;p&gt;Statistics provides the mathematical tools needed to do this. It helps a data scientist summarize a dataset, understand how variables behave, identify unusual observations, measure relationships, test assumptions, and make conclusions about populations using samples. Probability is also closely connected to statistics because real-world data contains uncertainty and randomness.&lt;/p&gt;

&lt;p&gt;A useful way to think about the role of statistics in data science is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collect data → Explore data → Summarize data → Analyze relationships → Test assumptions → Make conclusions → Build models&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  1. What Is Statistics?
&lt;/h1&gt;

&lt;p&gt;Statistics is the study of how to &lt;strong&gt;collect, organize, analyze, interpret, and communicate data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Suppose a company has information about 10,000 customers. The company might want to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the average amount customers spend?&lt;/li&gt;
&lt;li&gt;What percentage of customers are likely to leave?&lt;/li&gt;
&lt;li&gt;Which customer group spends the most?&lt;/li&gt;
&lt;li&gt;Is income related to spending?&lt;/li&gt;
&lt;li&gt;Did a new marketing campaign increase sales?&lt;/li&gt;
&lt;li&gt;How confident are we in our conclusions?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Statistics provides methods for answering these questions.&lt;/p&gt;

&lt;p&gt;In data science, statistics is particularly important because data scientists often work with samples rather than complete populations. Inferential statistics helps use sample information to draw conclusions about the larger population.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. Why Statistics Is Important in Data Science
&lt;/h1&gt;

&lt;p&gt;Statistics is used throughout the data science workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exploratory Data Analysis
&lt;/h3&gt;

&lt;p&gt;Statistics helps us understand a dataset before building a machine learning model.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Count&lt;/li&gt;
&lt;li&gt;Mean&lt;/li&gt;
&lt;li&gt;Standard deviation&lt;/li&gt;
&lt;li&gt;Minimum&lt;/li&gt;
&lt;li&gt;Quartiles&lt;/li&gt;
&lt;li&gt;Maximum&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Feature Selection
&lt;/h3&gt;

&lt;p&gt;Statistical techniques can help determine whether variables have useful relationships with a target variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Machine Learning
&lt;/h3&gt;

&lt;p&gt;Many machine learning techniques have statistical foundations. Understanding distributions, probability, sampling, variance, and estimation helps data scientists understand what models are doing rather than treating them as black boxes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Experimentation
&lt;/h3&gt;

&lt;p&gt;Statistics is essential for A/B testing and determining whether an observed difference is likely to represent a real effect rather than random variation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision Making
&lt;/h3&gt;

&lt;p&gt;Businesses can use statistical evidence to make decisions about customers, products, pricing, marketing, finance, and operations.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Types of Statistics
&lt;/h1&gt;

&lt;p&gt;Statistics can broadly be divided into two major areas:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    STATISTICS
                        │
            ┌───────────┴───────────┐
            │                       │
      DESCRIPTIVE              INFERENTIAL
      STATISTICS                STATISTICS
            │                       │
      Describe data          Draw conclusions
                              from samples
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Descriptive Statistics
&lt;/h2&gt;

&lt;p&gt;Descriptive statistics summarizes the data that has been collected.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mean&lt;/li&gt;
&lt;li&gt;Median&lt;/li&gt;
&lt;li&gt;Mode&lt;/li&gt;
&lt;li&gt;Range&lt;/li&gt;
&lt;li&gt;Variance&lt;/li&gt;
&lt;li&gt;Standard deviation&lt;/li&gt;
&lt;li&gt;Percentages&lt;/li&gt;
&lt;li&gt;Frequencies&lt;/li&gt;
&lt;li&gt;Quartiles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Descriptive statistics focuses on describing the observed data rather than making claims about data outside the dataset.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inferential Statistics
&lt;/h2&gt;

&lt;p&gt;Inferential statistics uses sample data to make conclusions about a larger population.&lt;/p&gt;

&lt;p&gt;For example, suppose a company has 100,000 customers but surveys only 1,000 of them.&lt;/p&gt;

&lt;p&gt;The sample can be analyzed to estimate characteristics of the larger customer population.&lt;/p&gt;

&lt;p&gt;Inferential statistics includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Confidence intervals&lt;/li&gt;
&lt;li&gt;Hypothesis testing&lt;/li&gt;
&lt;li&gt;t-tests&lt;/li&gt;
&lt;li&gt;Chi-square tests&lt;/li&gt;
&lt;li&gt;ANOVA&lt;/li&gt;
&lt;li&gt;Regression analysis&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  4. Population and Sample
&lt;/h1&gt;

&lt;p&gt;Two important concepts in statistics are &lt;strong&gt;population&lt;/strong&gt; and &lt;strong&gt;sample&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Population
&lt;/h3&gt;

&lt;p&gt;A population is the complete group we are interested in studying.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;All customers of a company.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Sample
&lt;/h3&gt;

&lt;p&gt;A sample is a smaller subset selected from the population.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1,000 customers selected from the company's 100,000 customers.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POPULATION
100,000 customers
        │
        │ Sampling
        ↓
SAMPLE
1,000 customers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Studying an entire population can be expensive, slow, or impossible. Therefore, data scientists frequently work with samples and use statistical methods to make inferences about the wider population.&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Measures of Central Tendency
&lt;/h1&gt;

&lt;p&gt;Central tendency describes the center or typical value of a dataset.&lt;/p&gt;

&lt;p&gt;The three most common measures are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mean&lt;/li&gt;
&lt;li&gt;Median&lt;/li&gt;
&lt;li&gt;Mode&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Mean
&lt;/h2&gt;

&lt;p&gt;The mean is the arithmetic average.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10, 20, 30, 40, 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The mean is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(10 + 20 + 30 + 40 + 50) / 5 = 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The mean is useful when the data is reasonably balanced, but it can be strongly affected by extreme values.&lt;/p&gt;




&lt;h2&gt;
  
  
  Median
&lt;/h2&gt;

&lt;p&gt;The median is the middle value after the observations have been arranged in order.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10, 20, 30, 40, 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The median is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For an even number of observations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10, 20, 30, 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the median is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(20 + 30) / 2 = 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The median is often more appropriate than the mean when data contains extreme outliers.&lt;/p&gt;

&lt;p&gt;For example, income data can be heavily skewed because a small number of people may earn extremely high incomes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mode
&lt;/h2&gt;

&lt;p&gt;The mode is the most frequently occurring value.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10, 20, 20, 30, 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The mode is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mode is particularly useful for categorical data.&lt;/p&gt;

&lt;p&gt;For example, if the most common customer payment method is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mobile Money
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then Mobile Money is the mode.&lt;/p&gt;




&lt;h1&gt;
  
  
  6. Measures of Dispersion
&lt;/h1&gt;

&lt;p&gt;Central tendency tells us where the data is centered, but it does not tell us how spread out the observations are.&lt;/p&gt;

&lt;p&gt;Measures of dispersion include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Range&lt;/li&gt;
&lt;li&gt;Variance&lt;/li&gt;
&lt;li&gt;Standard deviation&lt;/li&gt;
&lt;li&gt;Interquartile range&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Range
&lt;/h2&gt;

&lt;p&gt;Range is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Maximum - Minimum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10, 20, 30, 40, 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the range is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;50 - 10 = 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Variance
&lt;/h2&gt;

&lt;p&gt;Variance measures how far observations tend to be from the mean.&lt;/p&gt;

&lt;p&gt;A larger variance indicates greater spread.&lt;/p&gt;

&lt;p&gt;The population variance can be represented as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;σ² = Σ(x - μ)² / N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;σ²&lt;/code&gt; = population variance&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; = individual observation&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;μ&lt;/code&gt; = population mean&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;N&lt;/code&gt; = population size&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, Python can calculate variance directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Standard Deviation
&lt;/h2&gt;

&lt;p&gt;Standard deviation is the square root of variance.&lt;/p&gt;

&lt;p&gt;It provides a measure of the typical spread of observations around the mean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, a dataset with salaries tightly clustered around the average will have a smaller standard deviation than a dataset with salaries spread widely across different values.&lt;/p&gt;

&lt;p&gt;The distinction between standard deviation and standard error is important: standard deviation describes variability among observations, while standard error describes uncertainty in an estimate such as a sample mean.&lt;/p&gt;




&lt;h1&gt;
  
  
  7. Percentiles and Quartiles
&lt;/h1&gt;

&lt;p&gt;Percentiles divide data according to position.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;25th percentile&lt;/li&gt;
&lt;li&gt;50th percentile&lt;/li&gt;
&lt;li&gt;75th percentile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 50th percentile is the median.&lt;/p&gt;

&lt;p&gt;Quartiles divide data into four sections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Q1 = 25th percentile
Q2 = 50th percentile
Q3 = 75th percentile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;Interquartile Range (IQR)&lt;/strong&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IQR = Q3 - Q1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The IQR is particularly useful for identifying outliers.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. Understanding Distributions
&lt;/h1&gt;

&lt;p&gt;A distribution describes how values are spread across a dataset.&lt;/p&gt;

&lt;p&gt;One of the most important distributions in statistics is the &lt;strong&gt;normal distribution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A normal distribution is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symmetrical&lt;/li&gt;
&lt;li&gt;Bell-shaped&lt;/li&gt;
&lt;li&gt;Centered around its mean&lt;/li&gt;
&lt;li&gt;Characterized by its mean and standard deviation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a perfectly normal distribution, the mean, median, and mode are equal.&lt;/p&gt;

&lt;p&gt;Other important distributions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Binomial distribution&lt;/li&gt;
&lt;li&gt;Poisson distribution&lt;/li&gt;
&lt;li&gt;Uniform distribution&lt;/li&gt;
&lt;li&gt;Exponential distribution&lt;/li&gt;
&lt;li&gt;Bernoulli distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding probability distributions helps data scientists model uncertainty and choose appropriate statistical methods.&lt;/p&gt;




&lt;h1&gt;
  
  
  9. Probability
&lt;/h1&gt;

&lt;p&gt;Probability measures how likely an event is to occur.&lt;/p&gt;

&lt;p&gt;It ranges from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 → Impossible
1 → Certain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, if a fair coin is flipped:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(Heads) = 0.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Probability becomes important in data science because real-world datasets contain uncertainty.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What is the probability that a customer will default on a loan?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What is the probability that a transaction is fraudulent?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Probability forms part of the foundation for many statistical analyses and machine learning methods.&lt;/p&gt;




&lt;h1&gt;
  
  
  10. Correlation
&lt;/h1&gt;

&lt;p&gt;Correlation measures the strength and direction of a relationship between two variables.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hours studied ↑
        ↓
Exam score ↑
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If students who study more generally achieve higher scores, the two variables may have a positive correlation.&lt;/p&gt;

&lt;p&gt;Correlation coefficients typically range from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-1 to +1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Positive correlation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X ↑ → Y ↑
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Negative correlation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X ↑ → Y ↓
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  No linear correlation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;No clear linear relationship
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correlation is useful, but an important principle is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Correlation does not necessarily mean causation.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Two variables can be correlated without one directly causing the other.&lt;/p&gt;




&lt;h1&gt;
  
  
  11. Covariance
&lt;/h1&gt;

&lt;p&gt;Covariance measures how two variables change together.&lt;/p&gt;

&lt;p&gt;If two variables tend to increase together, covariance is positive.&lt;/p&gt;

&lt;p&gt;If one tends to increase while the other decreases, covariance is negative.&lt;/p&gt;

&lt;p&gt;Unlike correlation, covariance does not have a fixed range such as -1 to +1, which makes correlation easier to interpret when comparing relationships.&lt;/p&gt;




&lt;h1&gt;
  
  
  12. Hypothesis Testing
&lt;/h1&gt;

&lt;p&gt;Hypothesis testing is used to evaluate claims about a population using sample data.&lt;/p&gt;

&lt;p&gt;Suppose a company claims that a new training program increases employee productivity.&lt;/p&gt;

&lt;p&gt;We could define:&lt;/p&gt;

&lt;h3&gt;
  
  
  Null hypothesis
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H₀: The training program does not increase productivity.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Alternative hypothesis
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H₁: The training program increases productivity.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then collect data and perform an appropriate statistical test.&lt;/p&gt;




&lt;h1&gt;
  
  
  13. P-Values
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;p-value&lt;/strong&gt; is commonly used in hypothesis testing to quantify how compatible the observed data is with the null hypothesis under the assumptions of the test.&lt;/p&gt;

&lt;p&gt;A small p-value provides stronger evidence against the null hypothesis.&lt;/p&gt;

&lt;p&gt;For example, using a conventional significance level of 0.05:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p &amp;lt; 0.05
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may lead researchers to reject the null hypothesis.&lt;/p&gt;

&lt;p&gt;However, a p-value should not be interpreted as the probability that the null hypothesis is true. It also does not tell you how large or practically important an effect is.&lt;/p&gt;

&lt;p&gt;Statistical significance and practical significance are different concepts.&lt;/p&gt;




&lt;h1&gt;
  
  
  14. Type I and Type II Errors
&lt;/h1&gt;

&lt;p&gt;Hypothesis testing can produce two important types of errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type I Error
&lt;/h3&gt;

&lt;p&gt;A Type I error occurs when we reject a true null hypothesis.&lt;/p&gt;

&lt;p&gt;This is commonly described as a:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;False positive&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Concluding that a new medicine works when it actually does not.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Type II Error
&lt;/h3&gt;

&lt;p&gt;A Type II error occurs when we fail to reject a false null hypothesis.&lt;/p&gt;

&lt;p&gt;This is commonly described as a:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;False negative&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Concluding that a medicine does not work when it actually does.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  15. Confidence Intervals
&lt;/h1&gt;

&lt;p&gt;A confidence interval provides a range of plausible values for a population parameter based on sample data.&lt;/p&gt;

&lt;p&gt;For example, suppose a survey estimates that average customer spending is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KES 5,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with a 95% confidence interval of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KES 4,700 – KES 5,300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interval communicates uncertainty around the estimate.&lt;/p&gt;

&lt;p&gt;Confidence intervals are an important part of inferential statistics because sample statistics are estimates and therefore have uncertainty.&lt;/p&gt;




&lt;h1&gt;
  
  
  16. Statistical Tests
&lt;/h1&gt;

&lt;p&gt;Different questions require different statistical tests.&lt;/p&gt;

&lt;p&gt;Some common examples include:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Statistical Test&lt;/th&gt;
&lt;th&gt;Common Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;t-test&lt;/td&gt;
&lt;td&gt;Compare means&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chi-square test&lt;/td&gt;
&lt;td&gt;Analyze categorical variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ANOVA&lt;/td&gt;
&lt;td&gt;Compare means across multiple groups&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pearson correlation&lt;/td&gt;
&lt;td&gt;Measure linear association&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Regression&lt;/td&gt;
&lt;td&gt;Model relationships between variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mann-Whitney U&lt;/td&gt;
&lt;td&gt;Compare two groups without assuming normality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kruskal-Wallis&lt;/td&gt;
&lt;td&gt;Compare multiple groups without assuming normality&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The choice of test depends on factors such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data type&lt;/li&gt;
&lt;li&gt;Number of groups&lt;/li&gt;
&lt;li&gt;Sample size&lt;/li&gt;
&lt;li&gt;Distribution&lt;/li&gt;
&lt;li&gt;Independence&lt;/li&gt;
&lt;li&gt;Research question&lt;/li&gt;
&lt;li&gt;Statistical assumptions&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  17. Regression and Statistics
&lt;/h1&gt;

&lt;p&gt;Regression is another major statistical technique used in data science.&lt;/p&gt;

&lt;p&gt;For example, linear regression can model the relationship between an independent variable and a dependent variable.&lt;/p&gt;

&lt;p&gt;A simple linear regression equation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y = β₀ + β₁x + ε
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;y&lt;/code&gt; = dependent variable&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; = independent variable&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;β₀&lt;/code&gt; = intercept&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;β₁&lt;/code&gt; = coefficient&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ε&lt;/code&gt; = error term&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, we could investigate whether advertising expenditure is associated with sales.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Advertising Spend → Sales
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Regression can help with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prediction&lt;/li&gt;
&lt;li&gt;Understanding relationships&lt;/li&gt;
&lt;li&gt;Estimating effects&lt;/li&gt;
&lt;li&gt;Forecasting&lt;/li&gt;
&lt;li&gt;Feature analysis&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  18. Statistics and Machine Learning
&lt;/h1&gt;

&lt;p&gt;Statistics and machine learning are closely connected.&lt;/p&gt;

&lt;p&gt;Consider a classification problem where we want to predict whether a customer will leave a company.&lt;/p&gt;

&lt;p&gt;The dataset might contain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Age
Income
Tenure
Monthly spending
Number of complaints
Customer status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Statistics can help us:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Understand the variables.&lt;/li&gt;
&lt;li&gt;Identify missing values.&lt;/li&gt;
&lt;li&gt;Detect outliers.&lt;/li&gt;
&lt;li&gt;Examine distributions.&lt;/li&gt;
&lt;li&gt;Analyze relationships.&lt;/li&gt;
&lt;li&gt;Select useful features.&lt;/li&gt;
&lt;li&gt;Evaluate model performance.&lt;/li&gt;
&lt;li&gt;Quantify uncertainty.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Machine learning then uses algorithms to learn patterns from the data and make predictions.&lt;/p&gt;

&lt;p&gt;This is why a data scientist should not only know how to call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but should also understand what the data looks like and what assumptions may affect the model.&lt;/p&gt;




&lt;h1&gt;
  
  
  19. Statistics in Python
&lt;/h1&gt;

&lt;p&gt;Python provides several libraries for statistical analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pandas
&lt;/h3&gt;

&lt;p&gt;Pandas is commonly used for data manipulation and descriptive statistics.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can calculate individual statistics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  NumPy
&lt;/h3&gt;

&lt;p&gt;NumPy provides numerical and statistical functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  SciPy
&lt;/h3&gt;

&lt;p&gt;SciPy provides many statistical tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt;

&lt;span class="n"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ttest_ind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Statsmodels
&lt;/h3&gt;

&lt;p&gt;Statsmodels is useful for statistical modelling and detailed statistical inference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;statsmodels.api&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;sm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  20. Example: Analyzing Business Income
&lt;/h1&gt;

&lt;p&gt;Suppose a dataset contains the monthly income of several businesses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;30000
35000
40000
42000
50000
55000
60000
150000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could calculate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;personal_income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;personal_income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;personal_income&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extremely high value of &lt;code&gt;150000&lt;/code&gt; may affect the mean substantially.&lt;/p&gt;

&lt;p&gt;This is why it is important not to rely on a single statistic.&lt;/p&gt;

&lt;p&gt;A data scientist should examine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mean&lt;/li&gt;
&lt;li&gt;Median&lt;/li&gt;
&lt;li&gt;Standard deviation&lt;/li&gt;
&lt;li&gt;Distribution&lt;/li&gt;
&lt;li&gt;Outliers&lt;/li&gt;
&lt;li&gt;Quartiles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A boxplot can help identify potential outliers, while a histogram can show whether the distribution is symmetric or skewed.&lt;/p&gt;




&lt;h1&gt;
  
  
  21. The Central Limit Theorem
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Central Limit Theorem (CLT)&lt;/strong&gt; is one of the most important ideas in statistics.&lt;/p&gt;

&lt;p&gt;In simplified terms, when sufficiently large random samples are repeatedly drawn from a population, the distribution of their sample means tends toward a normal distribution under common conditions.&lt;/p&gt;

&lt;p&gt;This helps explain why statistical inference can work even when the original population distribution is not normal.&lt;/p&gt;

&lt;p&gt;The CLT is important for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Confidence intervals&lt;/li&gt;
&lt;li&gt;Hypothesis testing&lt;/li&gt;
&lt;li&gt;Sampling distributions&lt;/li&gt;
&lt;li&gt;Statistical estimation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding sampling distributions also helps explain the difference between the variability of individual observations and the uncertainty of estimated population parameters.&lt;/p&gt;




&lt;h1&gt;
  
  
  22. Common Statistical Mistakes in Data Science
&lt;/h1&gt;

&lt;p&gt;Knowing statistics is not only about knowing formulas. It is also about avoiding incorrect conclusions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 1: Assuming correlation means causation
&lt;/h3&gt;

&lt;p&gt;Two variables can move together without one causing the other.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 2: Ignoring outliers
&lt;/h3&gt;

&lt;p&gt;Extreme observations can strongly influence statistics such as the mean and some models.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 3: Using the wrong statistical test
&lt;/h3&gt;

&lt;p&gt;Different tests make different assumptions and answer different questions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 4: Focusing only on p-values
&lt;/h3&gt;

&lt;p&gt;A statistically significant result may have little practical importance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 5: Ignoring sample bias
&lt;/h3&gt;

&lt;p&gt;A large sample can still produce misleading conclusions if it is not representative of the population.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistake 6: Confusing standard deviation with standard error
&lt;/h3&gt;

&lt;p&gt;Standard deviation describes variation among observations, while standard error describes the uncertainty of an estimate.&lt;/p&gt;




&lt;h1&gt;
  
  
  23. A Practical Statistics Workflow for Data Scientists
&lt;/h1&gt;

&lt;p&gt;A useful workflow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Understand the dataset
          ↓
2. Identify variable types
          ↓
3. Check missing values
          ↓
4. Calculate descriptive statistics
          ↓
5. Visualize distributions
          ↓
6. Detect outliers
          ↓
7. Examine correlations
          ↓
8. Form statistical questions
          ↓
9. Choose appropriate tests
          ↓
10. Interpret the results
          ↓
11. Build statistical/ML models
          ↓
12. Communicate conclusions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach prevents the common mistake of immediately building a machine learning model without first understanding the data.&lt;/p&gt;




&lt;h1&gt;
  
  
  24. Statistics vs Machine Learning
&lt;/h1&gt;

&lt;p&gt;Statistics and machine learning overlap, but they often emphasize different goals.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Statistics&lt;/th&gt;
&lt;th&gt;Machine Learning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Understand relationships&lt;/td&gt;
&lt;td&gt;Make predictions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Estimate parameters&lt;/td&gt;
&lt;td&gt;Optimize predictive performance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test hypotheses&lt;/td&gt;
&lt;td&gt;Learn patterns from data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Quantify uncertainty&lt;/td&gt;
&lt;td&gt;Evaluate generalization&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Explain effects&lt;/td&gt;
&lt;td&gt;Predict outcomes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In practice, modern data scientists frequently use both.&lt;/p&gt;

&lt;p&gt;For example, a data scientist might use statistical analysis to understand which variables are associated with customer churn and then use machine learning to predict which customers are most likely to churn.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Statistics is not an optional skill for data scientists. It provides the foundation for understanding data, measuring uncertainty, testing ideas, and making evidence-based decisions.&lt;/p&gt;

&lt;p&gt;The most important areas to learn include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Descriptive statistics&lt;/li&gt;
&lt;li&gt;Inferential statistics&lt;/li&gt;
&lt;li&gt;Mean, median, and mode&lt;/li&gt;
&lt;li&gt;Variance and standard deviation&lt;/li&gt;
&lt;li&gt;Percentiles and quartiles&lt;/li&gt;
&lt;li&gt;Probability&lt;/li&gt;
&lt;li&gt;Probability distributions&lt;/li&gt;
&lt;li&gt;Sampling&lt;/li&gt;
&lt;li&gt;Correlation and covariance&lt;/li&gt;
&lt;li&gt;Hypothesis testing&lt;/li&gt;
&lt;li&gt;P-values&lt;/li&gt;
&lt;li&gt;Confidence intervals&lt;/li&gt;
&lt;li&gt;Statistical tests&lt;/li&gt;
&lt;li&gt;Regression&lt;/li&gt;
&lt;li&gt;Sampling distributions&lt;/li&gt;
&lt;li&gt;The Central Limit Theorem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most important mindset is to &lt;strong&gt;understand the data before trusting the model&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A machine learning algorithm can produce predictions, but statistics helps you understand whether the data supports those predictions, how uncertain your conclusions are, and whether the patterns you see are meaningful.&lt;/p&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Statistics helps data scientists turn data into evidence, and evidence into informed decisions.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>data</category>
      <category>datascience</category>
      <category>learning</category>
    </item>
    <item>
      <title># SQL Joins and Window Functions: A Practical Guide</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Wed, 19 Aug 2026 06:45:52 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/-sql-joins-and-window-functions-a-practical-guide-4dkg</link>
      <guid>https://dev.to/samuel_mwai/-sql-joins-and-window-functions-a-practical-guide-4dkg</guid>
      <description>&lt;h1&gt;
  
  
  SQL Joins and Window Functions: A Practical Guide
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;SQL is one of the most important tools for working with data. Whether you are analyzing sales, customers, employees, financial transactions, or business performance, SQL allows you to retrieve, combine, transform, and analyze data stored in relational databases.&lt;/p&gt;

&lt;p&gt;Two particularly important SQL concepts are &lt;strong&gt;joins&lt;/strong&gt; and &lt;strong&gt;window functions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Joins allow you to combine information from multiple tables, while window functions allow you to perform calculations across related rows without collapsing the individual rows.&lt;/p&gt;

&lt;p&gt;Understanding both concepts is essential for anyone working in data analysis, data science, business intelligence, or database development.&lt;/p&gt;




&lt;h1&gt;
  
  
  Part 1: SQL Joins
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What Is a SQL Join?
&lt;/h2&gt;

&lt;p&gt;A SQL join is used to combine rows from two or more tables based on a related column.&lt;/p&gt;

&lt;p&gt;For example, imagine we have two tables:&lt;/p&gt;

&lt;h3&gt;
  
  
  Customers
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;customer_name&lt;/th&gt;
&lt;th&gt;country&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Kenya&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;Uganda&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;Tanzania&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Orders
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;order_id&lt;/th&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;30000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;20000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The common column is &lt;code&gt;customer_id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can use it to connect the two tables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result would be:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer_name&lt;/th&gt;
&lt;th&gt;order_id&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;30000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;20000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The join allows us to combine customer information with order information.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. INNER JOIN
&lt;/h1&gt;

&lt;p&gt;An &lt;strong&gt;INNER JOIN&lt;/strong&gt; returns only rows that have matching values in both tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a customer has never placed an order, that customer will not appear in the result.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers          Orders

1 John             1
2 Mary             2
3 Peter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An inner join returns John and Mary because they have matching orders.&lt;/p&gt;

&lt;h3&gt;
  
  
  When to use INNER JOIN
&lt;/h3&gt;

&lt;p&gt;Use an inner join when you only want records that exist in both tables.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers who have placed orders&lt;/li&gt;
&lt;li&gt;Employees assigned to departments&lt;/li&gt;
&lt;li&gt;Products that have sales&lt;/li&gt;
&lt;li&gt;Students enrolled in courses&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2. LEFT JOIN
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;LEFT JOIN&lt;/strong&gt; returns every row from the left table and matching rows from the right table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result might be:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer_name&lt;/th&gt;
&lt;th&gt;order_id&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;30000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;20000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Peter appears even though he has no order.&lt;/p&gt;

&lt;p&gt;This is one of the most useful joins in data analysis because it allows you to find records that don't have matching information.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This finds customers who have never placed an order.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. RIGHT JOIN
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;RIGHT JOIN&lt;/strong&gt; returns every row from the right table and matching rows from the left table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;RIGHT JOIN is less commonly used because the same result can usually be achieved by switching the table order and using a LEFT JOIN.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is often easier to read.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. FULL OUTER JOIN
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;FULL OUTER JOIN&lt;/strong&gt; returns all rows from both tables.&lt;/p&gt;

&lt;p&gt;If a row has no match, SQL fills the missing values with &lt;code&gt;NULL&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;FULL&lt;/span&gt; &lt;span class="k"&gt;OUTER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful when you want to identify records that exist in one table but not the other.&lt;/p&gt;

&lt;p&gt;For example, you might use it to compare two datasets and find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers missing from another system&lt;/li&gt;
&lt;li&gt;Products missing from an inventory database&lt;/li&gt;
&lt;li&gt;Transactions that don't match&lt;/li&gt;
&lt;li&gt;Data quality problems&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  5. CROSS JOIN
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;CROSS JOIN&lt;/strong&gt; produces every possible combination of rows from two tables.&lt;/p&gt;

&lt;p&gt;Suppose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Products

Laptop
Phone
Tablet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Countries

Kenya
Uganda
Tanzania
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A cross join produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Laptop  Kenya
Laptop  Uganda
Laptop  Tanzania
Phone   Kenya
Phone   Uganda
Phone   Tanzania
Tablet  Kenya
Tablet  Uganda
Tablet  Tanzania
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;country&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="k"&gt;CROSS&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;countries&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If one table has 3 rows and another has 3 rows, the result contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 × 3 = 9 rows
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because cross joins can produce very large results, they should be used carefully.&lt;/p&gt;




&lt;h1&gt;
  
  
  6. SELF JOIN
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;SELF JOIN&lt;/strong&gt; joins a table to itself.&lt;/p&gt;

&lt;p&gt;This is useful when records within the same table are related.&lt;/p&gt;

&lt;p&gt;For example, an employee table might contain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee_id&lt;/th&gt;
&lt;th&gt;employee_name&lt;/th&gt;
&lt;th&gt;manager_id&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here, &lt;code&gt;manager_id&lt;/code&gt; refers back to &lt;code&gt;employee_id&lt;/code&gt; in the same table.&lt;/p&gt;

&lt;p&gt;We can use a self join to display each employee and their manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;employee_name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;employee_name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;manager_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;employee_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;manager&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h1&gt;
  
  
  Part 2: SQL Window Functions
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What Is a Window Function?
&lt;/h2&gt;

&lt;p&gt;A window function performs a calculation across a set of related rows while &lt;strong&gt;keeping the individual rows in the result&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is the key difference between window functions and regular aggregate functions.&lt;/p&gt;

&lt;p&gt;For example, consider:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;department&lt;/th&gt;
&lt;th&gt;salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;60000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jane&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;80000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A regular aggregation might calculate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;department&lt;/th&gt;
&lt;th&gt;average_salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;65000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;65000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The individual employees disappear from the result.&lt;/p&gt;

&lt;p&gt;A window function allows us to calculate the average while keeping every employee:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;department_average&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;department&lt;/th&gt;
&lt;th&gt;salary&lt;/th&gt;
&lt;th&gt;department_average&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;60000&lt;/td&gt;
&lt;td&gt;65000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;td&gt;65000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;td&gt;65000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jane&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;80000&lt;/td&gt;
&lt;td&gt;65000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is why window functions are extremely powerful for analytics.&lt;/p&gt;




&lt;h1&gt;
  
  
  7. The OVER() Clause
&lt;/h1&gt;

&lt;p&gt;Window functions use the &lt;code&gt;OVER()&lt;/code&gt; clause.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;OVER()&lt;/code&gt; clause tells SQL that we want the calculation to operate as a window over the result set.&lt;/p&gt;

&lt;p&gt;There are two particularly important components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  8. PARTITION BY
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;PARTITION BY&lt;/code&gt; divides the data into groups for the window calculation.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This calculates the average salary separately for each department.&lt;/p&gt;

&lt;p&gt;It is similar to &lt;code&gt;GROUP BY&lt;/code&gt;, but it does &lt;strong&gt;not&lt;/strong&gt; collapse the rows.&lt;/p&gt;

&lt;p&gt;Think of it as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GROUP BY → reduces rows

PARTITION BY → keeps rows
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  9. ORDER BY in Window Functions
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;ORDER BY&lt;/code&gt; determines the order in which the window function processes rows.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be used to calculate a running total.&lt;/p&gt;

&lt;p&gt;Suppose we have:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;sale_date&lt;/th&gt;
&lt;th&gt;sales&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jan 1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 2&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 3&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;sale_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;running_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;sale_date&lt;/th&gt;
&lt;th&gt;sales&lt;/th&gt;
&lt;th&gt;running_sales&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jan 1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 2&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 3&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;450&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is called a &lt;strong&gt;running total&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  10. ROW_NUMBER()
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;ROW_NUMBER()&lt;/code&gt; assigns a unique sequential number to each row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;row_number&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;salary&lt;/th&gt;
&lt;th&gt;row_number&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jane&lt;/td&gt;
&lt;td&gt;80000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;60000&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can also partition the results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
    &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ranks employees separately within each department.&lt;/p&gt;




&lt;h1&gt;
  
  
  11. RANK()
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;RANK()&lt;/code&gt; assigns rankings but gives tied values the same rank.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jane&lt;/td&gt;
&lt;td&gt;80000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;salary_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;salary&lt;/th&gt;
&lt;th&gt;salary_rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jane&lt;/td&gt;
&lt;td&gt;80000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice that there is no rank 3 because Mary and John share rank 2.&lt;/p&gt;




&lt;h1&gt;
  
  
  12. DENSE_RANK()
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;DENSE_RANK()&lt;/code&gt; is similar to &lt;code&gt;RANK()&lt;/code&gt;, but it does not skip ranking numbers.&lt;/p&gt;

&lt;p&gt;Using the same data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;DENSE_RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;salary_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;employee&lt;/th&gt;
&lt;th&gt;salary&lt;/th&gt;
&lt;th&gt;salary_rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jane&lt;/td&gt;
&lt;td&gt;80000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;70000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The difference is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ROW_NUMBER()
1, 2, 3, 4

RANK()
1, 2, 2, 4

DENSE_RANK()
1, 2, 2, 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  13. LAG()
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;LAG()&lt;/code&gt; allows you to access a value from a previous row.&lt;/p&gt;

&lt;p&gt;This is extremely useful when analyzing changes over time.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;sale_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;previous_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;sale_date&lt;/th&gt;
&lt;th&gt;sales&lt;/th&gt;
&lt;th&gt;previous_sales&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jan 1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 2&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 3&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We can then calculate the change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;sale_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;sales_change&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;sale_date&lt;/th&gt;
&lt;th&gt;sales&lt;/th&gt;
&lt;th&gt;sales_change&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jan 1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 2&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 3&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;-50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Month-over-month analysis&lt;/li&gt;
&lt;li&gt;Year-over-year analysis&lt;/li&gt;
&lt;li&gt;Stock analysis&lt;/li&gt;
&lt;li&gt;Customer activity&lt;/li&gt;
&lt;li&gt;Revenue changes&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  14. LEAD()
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;LEAD()&lt;/code&gt; does the opposite of &lt;code&gt;LAG()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It allows you to access a value from a future row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;sale_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;LEAD&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;next_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;sale_date&lt;/th&gt;
&lt;th&gt;sales&lt;/th&gt;
&lt;th&gt;next_sales&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jan 1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 2&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 3&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h1&gt;
  
  
  15. FIRST_VALUE() and LAST_VALUE()
&lt;/h1&gt;

&lt;p&gt;Window functions can also retrieve the first or last value within a window.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;FIRST_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;highest_salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows every employee to see the highest salary within their department.&lt;/p&gt;




&lt;h1&gt;
  
  
  16. Window Functions vs GROUP BY
&lt;/h1&gt;

&lt;p&gt;One of the most important concepts to understand is the difference between &lt;code&gt;GROUP BY&lt;/code&gt; and window functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  GROUP BY
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;average_salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Produces one row per department.&lt;/p&gt;

&lt;h3&gt;
  
  
  Window Function
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;average_salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keeps every employee while adding the department average.&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GROUP BY summarizes rows.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Window functions analyze rows without removing them.&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  17. Combining Joins and Window Functions
&lt;/h1&gt;

&lt;p&gt;Joins and window functions are often used together in real-world data analysis.&lt;/p&gt;

&lt;p&gt;Suppose you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers
Orders
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could first join the tables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use a window function to rank each customer's orders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;order_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can identify the largest order for each customer.&lt;/p&gt;




&lt;h1&gt;
  
  
  18. Finding the Top Record per Group
&lt;/h1&gt;

&lt;p&gt;One of the most common real-world uses of window functions is finding the top record within each group.&lt;/p&gt;

&lt;p&gt;For example, suppose you want the highest-paid employee in every department.&lt;/p&gt;

&lt;p&gt;First:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rn&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use a subquery:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;
            &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rn&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ranked&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns the highest-paid employee from each department.&lt;/p&gt;




&lt;h1&gt;
  
  
  19. Real-World Applications
&lt;/h1&gt;

&lt;p&gt;SQL joins and window functions are widely used in data analytics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sales Analysis
&lt;/h3&gt;

&lt;p&gt;You can use joins to combine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers
Products
Orders
Sales
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use window functions to calculate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer rankings&lt;/li&gt;
&lt;li&gt;Running revenue&lt;/li&gt;
&lt;li&gt;Previous month's sales&lt;/li&gt;
&lt;li&gt;Top products&lt;/li&gt;
&lt;li&gt;Sales growth&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Financial Analysis
&lt;/h3&gt;

&lt;p&gt;Window functions can be used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running balances&lt;/li&gt;
&lt;li&gt;Transaction rankings&lt;/li&gt;
&lt;li&gt;Month-over-month changes&lt;/li&gt;
&lt;li&gt;Portfolio performance&lt;/li&gt;
&lt;li&gt;Cumulative revenue&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Human Resources
&lt;/h3&gt;

&lt;p&gt;You can calculate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Employee salary rankings&lt;/li&gt;
&lt;li&gt;Department averages&lt;/li&gt;
&lt;li&gt;Highest-paid employees&lt;/li&gt;
&lt;li&gt;Employee salary differences&lt;/li&gt;
&lt;li&gt;Hiring trends&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Customer Analytics
&lt;/h3&gt;

&lt;p&gt;You can analyze:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First purchase&lt;/li&gt;
&lt;li&gt;Most recent purchase&lt;/li&gt;
&lt;li&gt;Customer order rankings&lt;/li&gt;
&lt;li&gt;Previous purchases&lt;/li&gt;
&lt;li&gt;Customer spending trends&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  20. Best Practices
&lt;/h1&gt;

&lt;p&gt;When working with joins and window functions, several practices can make your SQL easier to understand and more reliable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use table aliases
&lt;/h3&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after defining:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Always specify the join condition
&lt;/h3&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoid accidentally creating a Cartesian product unless you intentionally need a &lt;code&gt;CROSS JOIN&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understand your keys
&lt;/h3&gt;

&lt;p&gt;Before joining tables, determine whether the join key is unique.&lt;/p&gt;

&lt;p&gt;Joining a one-to-many table incorrectly can create duplicate rows and inflate totals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use meaningful window ordering
&lt;/h3&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is meaningful for a running sales calculation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use PARTITION BY when analysis needs groups
&lt;/h3&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;allows calculations to restart for every customer.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;SQL joins and window functions are essential skills for data analysts and data scientists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Joins allow you to bring information from different tables together&lt;/strong&gt;, while &lt;strong&gt;window functions allow you to analyze related rows while preserving the original rows&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The most important joins to understand are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;INNER JOIN&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LEFT JOIN&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RIGHT JOIN&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FULL OUTER JOIN&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CROSS JOIN&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SELF JOIN&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most useful window functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ROW_NUMBER()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RANK()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DENSE_RANK()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LAG()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LEAD()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SUM() OVER()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;AVG() OVER()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FIRST_VALUE()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LAST_VALUE()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple way to remember the concepts is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Joins combine tables. Window functions analyze rows.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you understand these two concepts, you can solve much more advanced SQL problems, from identifying top-performing customers to calculating running totals and comparing current performance with previous periods.&lt;/p&gt;

</description>
      <category>database</category>
      <category>datascience</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Data Modelling in Power BI: Joins, Relationships and Schemas Explained</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Wed, 19 Aug 2026 06:41:42 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/data-modelling-in-power-bi-joins-relationships-and-schemas-explained-47ln</link>
      <guid>https://dev.to/samuel_mwai/data-modelling-in-power-bi-joins-relationships-and-schemas-explained-47ln</guid>
      <description>&lt;p&gt;Data modelling is one of the most important concepts in Power BI. A good data model allows reports to produce accurate results, perform efficiently, and remain easy to maintain. A poor data model, on the other hand, can lead to incorrect calculations, confusing relationships, duplicate data, and slow reports.&lt;/p&gt;

&lt;p&gt;In Power BI, data modelling involves organising tables and defining how those tables interact with one another. Three concepts are particularly important: &lt;strong&gt;joins, relationships, and schemas&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. What Is Data Modelling?
&lt;/h2&gt;

&lt;p&gt;Data modelling is the process of organising data into tables and defining the connections between those tables.&lt;/p&gt;

&lt;p&gt;For example, imagine a company has three tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Customers&lt;/strong&gt; – contains customer information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Products&lt;/strong&gt; – contains product information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sales&lt;/strong&gt; – contains information about each sale.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Sales table might contain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;SaleID&lt;/th&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;ProductID&lt;/th&gt;
&lt;th&gt;Quantity&lt;/th&gt;
&lt;th&gt;SalesAmount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1001&lt;/td&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;P01&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1002&lt;/td&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;P03&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1,500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1003&lt;/td&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;P02&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;3,200&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Customers table could contain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;CustomerName&lt;/th&gt;
&lt;th&gt;Country&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Kenya&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;Uganda&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Products table could contain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;ProductID&lt;/th&gt;
&lt;th&gt;ProductName&lt;/th&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;P01&lt;/td&gt;
&lt;td&gt;Laptop&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;P02&lt;/td&gt;
&lt;td&gt;Monitor&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;P03&lt;/td&gt;
&lt;td&gt;Printer&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Power BI can connect these tables using &lt;strong&gt;CustomerID&lt;/strong&gt; and &lt;strong&gt;ProductID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This creates a data model that allows us to answer questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How much did each customer spend?&lt;/li&gt;
&lt;li&gt;Which products generated the most revenue?&lt;/li&gt;
&lt;li&gt;Which country generated the highest sales?&lt;/li&gt;
&lt;li&gt;How many products were sold in each category?&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2. Joins Explained
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;join&lt;/strong&gt; combines data from two or more tables based on a common column.&lt;/p&gt;

&lt;p&gt;Joins are commonly encountered when using &lt;strong&gt;Power Query&lt;/strong&gt; in Power BI.&lt;/p&gt;

&lt;p&gt;For example, suppose we have:&lt;/p&gt;

&lt;h3&gt;
  
  
  Customers
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;CustomerName&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C003&lt;/td&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Sales
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;SalesAmount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;2000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;1500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C004&lt;/td&gt;
&lt;td&gt;3000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The common column is &lt;code&gt;CustomerID&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A join can combine these tables using that column.&lt;/p&gt;




&lt;h2&gt;
  
  
  Types of Joins
&lt;/h2&gt;

&lt;p&gt;Power Query provides several join types.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inner Join
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;Inner Join&lt;/strong&gt; returns only records that exist in both tables.&lt;/p&gt;

&lt;p&gt;In our example, C001 and C002 exist in both tables, while C003 and C004 do not.&lt;/p&gt;

&lt;p&gt;The result would be:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;CustomerName&lt;/th&gt;
&lt;th&gt;SalesAmount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;1500&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Inner joins are useful when you only want records with matching values in both tables.&lt;/p&gt;




&lt;h3&gt;
  
  
  Left Outer Join
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Left Outer Join&lt;/strong&gt; keeps every record from the left table and adds matching records from the right table.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;CustomerName&lt;/th&gt;
&lt;th&gt;SalesAmount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;1500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C003&lt;/td&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;null&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Peter remains in the result because he exists in the left table, even though he has no matching sales record.&lt;/p&gt;

&lt;p&gt;This is one of the most commonly used joins.&lt;/p&gt;




&lt;h3&gt;
  
  
  Right Outer Join
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Right Outer Join&lt;/strong&gt; keeps every record from the right table and adds matching records from the left table.&lt;/p&gt;

&lt;p&gt;Using our example, C004 would be included because it exists in the right table.&lt;/p&gt;




&lt;h3&gt;
  
  
  Full Outer Join
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Full Outer Join&lt;/strong&gt; keeps all records from both tables.&lt;/p&gt;

&lt;p&gt;It includes matching and non-matching records.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;CustomerName&lt;/th&gt;
&lt;th&gt;SalesAmount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;1500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C003&lt;/td&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;td&gt;null&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C004&lt;/td&gt;
&lt;td&gt;null&lt;/td&gt;
&lt;td&gt;3000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Anti Joins
&lt;/h3&gt;

&lt;p&gt;Anti joins are useful for finding records that &lt;strong&gt;do not have a match&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, a Left Anti Join could identify customers who have never made a purchase.&lt;/p&gt;

&lt;p&gt;This can be extremely useful for data-quality checks and business analysis.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Joins vs Relationships
&lt;/h1&gt;

&lt;p&gt;Joins and relationships are related concepts, but they are &lt;strong&gt;not the same thing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;join&lt;/strong&gt; physically combines columns from tables into a new table during data preparation.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;relationship&lt;/strong&gt; connects existing tables within the Power BI data model.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers
CustomerID
CustomerName
Country
      |
      | CustomerID
      |
      ↓
Sales
SaleID
CustomerID
ProductID
SalesAmount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tables remain separate, but Power BI knows how they are connected.&lt;/p&gt;

&lt;p&gt;This distinction is important.&lt;/p&gt;

&lt;h3&gt;
  
  
  Joins are mainly used for:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Combining columns&lt;/li&gt;
&lt;li&gt;Cleaning data&lt;/li&gt;
&lt;li&gt;Preparing data&lt;/li&gt;
&lt;li&gt;Creating a new query/table&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Relationships are mainly used for:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Connecting tables&lt;/li&gt;
&lt;li&gt;Filtering data&lt;/li&gt;
&lt;li&gt;Creating measures&lt;/li&gt;
&lt;li&gt;Building reports&lt;/li&gt;
&lt;li&gt;Supporting DAX calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In many Power BI models, it is better to keep related tables separate rather than repeatedly joining everything into one large table.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. Relationships in Power BI
&lt;/h1&gt;

&lt;p&gt;A relationship tells Power BI how two tables are connected.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers[CustomerID]
          |
          |
          ↓
Sales[CustomerID]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Power BI can then understand that a particular sale belongs to a particular customer.&lt;/p&gt;

&lt;p&gt;Relationships are created using columns that contain related values.&lt;/p&gt;

&lt;p&gt;Usually, one table contains a unique value while another table contains repeated values.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;h3&gt;
  
  
  Customers
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;CustomerName&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C003&lt;/td&gt;
&lt;td&gt;Peter&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each CustomerID appears once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sales
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;SaleID&lt;/th&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;Amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;C001&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;C002&lt;/td&gt;
&lt;td&gt;800&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;CustomerID can appear many times in Sales.&lt;/p&gt;

&lt;p&gt;This creates a &lt;strong&gt;one-to-many relationship&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Cardinality
&lt;/h1&gt;

&lt;p&gt;Cardinality describes how many records in one table can be related to records in another table.&lt;/p&gt;

&lt;p&gt;Power BI supports several types.&lt;/p&gt;

&lt;h2&gt;
  
  
  One-to-Many (1:*)
&lt;/h2&gt;

&lt;p&gt;This is the most common relationship in a well-designed Power BI model.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers  1 ───────── *  Sales
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One customer can have many sales.&lt;/p&gt;

&lt;p&gt;The Customers table is the &lt;strong&gt;one&lt;/strong&gt; side, while Sales is the &lt;strong&gt;many&lt;/strong&gt; side.&lt;/p&gt;




&lt;h2&gt;
  
  
  Many-to-One (*:1)
&lt;/h2&gt;

&lt;p&gt;This is essentially the same relationship viewed from the opposite direction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sales  * ───────── 1  Customers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many sales belong to one customer.&lt;/p&gt;




&lt;h2&gt;
  
  
  One-to-One (1:1)
&lt;/h2&gt;

&lt;p&gt;Each record in one table corresponds to exactly one record in another table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Employee  1 ───────── 1  EmployeeDetails
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This relationship is less common and should be used carefully.&lt;/p&gt;




&lt;h2&gt;
  
  
  Many-to-Many (&lt;em&gt;:&lt;/em&gt;)
&lt;/h2&gt;

&lt;p&gt;Multiple records in one table can correspond to multiple records in another.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Students  * ─────── *  Courses
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A student can take many courses, while a course can have many students.&lt;/p&gt;

&lt;p&gt;Many-to-many relationships can be useful, but they can also create ambiguity and unexpected filtering behaviour. A bridge table is often a better solution.&lt;/p&gt;




&lt;h1&gt;
  
  
  6. Primary Keys and Foreign Keys
&lt;/h1&gt;

&lt;p&gt;Relationships usually depend on &lt;strong&gt;keys&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;primary key&lt;/strong&gt; uniquely identifies each record in a table.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CustomerID
C001
C002
C003
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each CustomerID is unique.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;foreign key&lt;/strong&gt; is a column that refers to a key in another table.&lt;/p&gt;

&lt;p&gt;For example, the Sales table may contain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CustomerID
C001
C001
C002
C003
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, CustomerID is a foreign key because it refers to CustomerID in the Customers table.&lt;/p&gt;

&lt;p&gt;A typical model therefore looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers
----------
CustomerID ← Primary Key
CustomerName
Country

       1
       |
       |
       *
Sales
----------
SaleID ← Primary Key
CustomerID ← Foreign Key
SalesAmount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  7. Schemas Explained
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;schema&lt;/strong&gt; is the overall structure or organisation of tables and their relationships.&lt;/p&gt;

&lt;p&gt;When working with Power BI, two important schema designs are the &lt;strong&gt;Star Schema&lt;/strong&gt; and &lt;strong&gt;Snowflake Schema&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. Star Schema
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Star Schema&lt;/strong&gt; is generally the preferred modelling approach for Power BI.&lt;/p&gt;

&lt;p&gt;It gets its name because the model looks like a star.&lt;/p&gt;

&lt;p&gt;At the centre is a &lt;strong&gt;fact table&lt;/strong&gt;, surrounded by &lt;strong&gt;dimension tables&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Customers
                     |
                     |
Products ─────── Sales ─────── Date
                     |
                     |
                 Employees
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The central Sales table is the &lt;strong&gt;fact table&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The surrounding tables are &lt;strong&gt;dimension tables&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fact Tables
&lt;/h2&gt;

&lt;p&gt;A fact table contains business events or transactions.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sales
----------------
SaleID
DateID
CustomerID
ProductID
Quantity
SalesAmount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A fact table normally contains numerical values that can be aggregated, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sales&lt;/li&gt;
&lt;li&gt;Revenue&lt;/li&gt;
&lt;li&gt;Quantity&lt;/li&gt;
&lt;li&gt;Cost&lt;/li&gt;
&lt;li&gt;Profit&lt;/li&gt;
&lt;li&gt;Discount&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These values are often called &lt;strong&gt;measures&lt;/strong&gt; or metrics.&lt;/p&gt;




&lt;h2&gt;
  
  
  Dimension Tables
&lt;/h2&gt;

&lt;p&gt;Dimension tables provide descriptive information about the facts.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;h3&gt;
  
  
  Customer Dimension
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CustomerID
CustomerName
Gender
Country
Age
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Product Dimension
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ProductID
ProductName
Category
Brand
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Date Dimension
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DateID
Date
Year
Month
Quarter
Day
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dimensions allow users to analyse facts from different perspectives.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Total sales by country&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;uses the &lt;strong&gt;Customer dimension&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Total sales by product category&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;uses the &lt;strong&gt;Product dimension&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Total sales by month&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;uses the &lt;strong&gt;Date dimension&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  9. Snowflake Schema
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;Snowflake Schema&lt;/strong&gt; is similar to a Star Schema, but dimension tables are further divided into additional tables.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Country
                    |
                    |
Customers ─────── Sales ─────── Products
                                |
                                |
                             Category
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of keeping all product information in one Products table, some information may be separated into another table.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Products
---------
ProductID
ProductName
CategoryID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Categories
----------
CategoryID
CategoryName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces repeated information but creates additional relationships.&lt;/p&gt;




&lt;h1&gt;
  
  
  10. Star Schema vs Snowflake Schema
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Star Schema&lt;/th&gt;
&lt;th&gt;Snowflake Schema&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Structure&lt;/td&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;More complex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dimensions&lt;/td&gt;
&lt;td&gt;Usually denormalised&lt;/td&gt;
&lt;td&gt;More normalised&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Number of tables&lt;/td&gt;
&lt;td&gt;Fewer&lt;/td&gt;
&lt;td&gt;More&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Relationships&lt;/td&gt;
&lt;td&gt;Easier&lt;/td&gt;
&lt;td&gt;More complex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Power BI usability&lt;/td&gt;
&lt;td&gt;Excellent&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Report development&lt;/td&gt;
&lt;td&gt;Easier&lt;/td&gt;
&lt;td&gt;More difficult&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Often very good&lt;/td&gt;
&lt;td&gt;Can require more relationship navigation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For most Power BI reporting projects, a &lt;strong&gt;Star Schema is usually the preferred starting point&lt;/strong&gt; because it is simple, intuitive, and works well with Power BI's analytical engine.&lt;/p&gt;




&lt;h1&gt;
  
  
  11. Filter Direction
&lt;/h1&gt;

&lt;p&gt;Relationships also have a concept called &lt;strong&gt;cross-filter direction&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The two common options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single&lt;/li&gt;
&lt;li&gt;Both&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With a single-direction relationship:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customers  →  Sales
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Filters generally flow from the Customers table toward Sales.&lt;/p&gt;

&lt;p&gt;For example, selecting Kenya in the Customers table can filter the Sales table to show sales from Kenya.&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;Both&lt;/strong&gt;, filtering can flow in both directions.&lt;/p&gt;

&lt;p&gt;Although bidirectional filtering can be useful in some situations, it should not be used everywhere because it can introduce ambiguous filter paths and make models harder to understand.&lt;/p&gt;

&lt;p&gt;A good model generally uses &lt;strong&gt;single-direction filtering where possible&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  12. Why Data Modelling Matters
&lt;/h1&gt;

&lt;p&gt;Good data modelling provides several benefits.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Accurate Results
&lt;/h3&gt;

&lt;p&gt;Relationships determine how filters move through your model. Incorrect relationships can produce incorrect totals and calculations.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Better Performance
&lt;/h3&gt;

&lt;p&gt;A properly designed model can reduce unnecessary data duplication and improve report performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Easier DAX
&lt;/h3&gt;

&lt;p&gt;Measures become easier to write when tables have clear relationships.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total Sales = SUM(Sales[SalesAmount])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then analyse Total Sales by customer, product, country, or date without having to manually combine the tables inside every calculation.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Easier Report Development
&lt;/h3&gt;

&lt;p&gt;A clean model makes it easier to drag fields into visuals and understand where each field comes from.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Easier Maintenance
&lt;/h3&gt;

&lt;p&gt;If the business changes, a well-structured model is easier to update.&lt;/p&gt;




&lt;h1&gt;
  
  
  13. Common Data Modelling Mistakes
&lt;/h1&gt;

&lt;p&gt;Several mistakes frequently occur when building Power BI models.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating One Huge Table
&lt;/h3&gt;

&lt;p&gt;Beginners often join every table together into one massive table.&lt;/p&gt;

&lt;p&gt;Although this may seem easier, it can result in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicate information&lt;/li&gt;
&lt;li&gt;Larger datasets&lt;/li&gt;
&lt;li&gt;More complicated calculations&lt;/li&gt;
&lt;li&gt;Poorer performance&lt;/li&gt;
&lt;li&gt;Difficult maintenance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Star Schema is often a better approach.&lt;/p&gt;




&lt;h3&gt;
  
  
  Creating Incorrect Relationships
&lt;/h3&gt;

&lt;p&gt;For example, connecting two tables using columns that do not uniquely identify records can produce incorrect results.&lt;/p&gt;

&lt;p&gt;Always understand the meaning of the columns before creating a relationship.&lt;/p&gt;




&lt;h3&gt;
  
  
  Using Many-to-Many Unnecessarily
&lt;/h3&gt;

&lt;p&gt;Many-to-many relationships can create unexpected results.&lt;/p&gt;

&lt;p&gt;Where appropriate, consider introducing a bridge table.&lt;/p&gt;




&lt;h3&gt;
  
  
  Duplicate Values on the "One" Side
&lt;/h3&gt;

&lt;p&gt;The one side of a one-to-many relationship should normally contain unique values.&lt;/p&gt;

&lt;p&gt;For example, if CustomerID appears multiple times in the Customers table, Power BI cannot treat it as a proper one-side key.&lt;/p&gt;




&lt;h3&gt;
  
  
  Unnecessary Bidirectional Relationships
&lt;/h3&gt;

&lt;p&gt;Setting every relationship to Both can make a model complicated and introduce ambiguous filtering.&lt;/p&gt;

&lt;p&gt;Use it only when there is a clear reason.&lt;/p&gt;




&lt;h1&gt;
  
  
  14. A Practical Power BI Model
&lt;/h1&gt;

&lt;p&gt;Imagine you are analysing a company's sales data.&lt;/p&gt;

&lt;p&gt;You might have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 DimCustomer
                      |
                      |
DimProduct ───── FactSales ───── DimDate
                      |
                      |
                 DimEmployee
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The FactSales table contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SaleID
CustomerID
ProductID
DateID
EmployeeID
Quantity
SalesAmount
Cost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dimension tables contain descriptive information.&lt;/p&gt;

&lt;p&gt;You could then create measures such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total Sales = SUM(FactSales[SalesAmount])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total Cost = SUM(FactSales[Cost])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Profit = [Total Sales] - [Total Cost]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the relationships are correctly established, you can place &lt;strong&gt;Country&lt;/strong&gt;, &lt;strong&gt;Product Category&lt;/strong&gt;, or &lt;strong&gt;Year&lt;/strong&gt; in a visual and Power BI can automatically filter the sales data appropriately.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Data modelling is the foundation of an effective Power BI report. Understanding the difference between &lt;strong&gt;joins, relationships, and schemas&lt;/strong&gt; is essential for building reliable data models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Joins&lt;/strong&gt; are primarily used to combine tables during data preparation, especially in Power Query. &lt;strong&gt;Relationships&lt;/strong&gt; connect tables within the Power BI data model and allow filters and calculations to work across those tables. &lt;strong&gt;Schemas&lt;/strong&gt; describe how the overall model is organised, with the &lt;strong&gt;Star Schema&lt;/strong&gt; being one of the most useful designs for Power BI.&lt;/p&gt;

&lt;p&gt;A strong Power BI model usually has a clear fact table, well-defined dimension tables, appropriate one-to-many relationships, unique keys, and sensible filter directions.&lt;/p&gt;

&lt;p&gt;The goal is not simply to connect every table together. The goal is to create a model that represents the business logically, makes calculations reliable, and allows users to analyse their data efficiently.&lt;/p&gt;

&lt;p&gt;Once you understand &lt;strong&gt;joins → relationships → cardinality → fact and dimension tables → Star Schema&lt;/strong&gt;, you have the foundation needed to build much more professional Power BI reports.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>data</category>
      <category>database</category>
    </item>
    <item>
      <title># Statistics: Parametric and Non-Parametric Tests in Data Science</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Mon, 17 Aug 2026 09:55:07 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/-statistics-parametric-and-non-parametric-tests-in-data-science-49gc</link>
      <guid>https://dev.to/samuel_mwai/-statistics-parametric-and-non-parametric-tests-in-data-science-49gc</guid>
      <description>&lt;h1&gt;
  
  
  Statistics: Parametric and Non-Parametric Tests in Data Science
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fo_GwrTmN0O6FjzHl4lfJSAyrHAjFKf-pXsOUj1FfFtwiwmzldCSFfVuoIY7gWQ7n0I0SGU6eDtXDsrienZLHersHf57KfhhGKWdod067oQ0bZ6yHvND2nRg5pxuxAYTXpD0KGbH292__oXkt62j3vxxMpy9w77kXAJgcWQp3zDVW7m88JV-yw7337MXBH-kI%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fo_GwrTmN0O6FjzHl4lfJSAyrHAjFKf-pXsOUj1FfFtwiwmzldCSFfVuoIY7gWQ7n0I0SGU6eDtXDsrienZLHersHf57KfhhGKWdod067oQ0bZ6yHvND2nRg5pxuxAYTXpD0KGbH292__oXkt62j3vxxMpy9w77kXAJgcWQp3zDVW7m88JV-yw7337MXBH-kI%3Fpurpose%3Dfullsize" alt="Image" width="1400" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FwTdTArb0dJVWjD7t_Oo5kM6ypNm_U74aN-QVAndkAmMTV0cRDWSBpzLJFuvM73qC-41z4sP2FEoObOuJYB4FfvUyBOQPVhui9EtP06l5mbRRYVt3n1IUC6Ek1wF0XiTFYBa-J94oD_AflKqZfcPtOOx9YVtZ9eziNlKhIK4qXVqYY_aciO9h9kuie7hT6zq1%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FwTdTArb0dJVWjD7t_Oo5kM6ypNm_U74aN-QVAndkAmMTV0cRDWSBpzLJFuvM73qC-41z4sP2FEoObOuJYB4FfvUyBOQPVhui9EtP06l5mbRRYVt3n1IUC6Ek1wF0XiTFYBa-J94oD_AflKqZfcPtOOx9YVtZ9eziNlKhIK4qXVqYY_aciO9h9kuie7hT6zq1%3Fpurpose%3Dfullsize" alt="Image" width="1275" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FUvMIQ06uST8nVYdX4u8dgREdF2tJcISTBBJ-lvlOlnf6Fu78tiIq54UktktDPuI1jZmbb5Ux8GBYT1RO72giBYtAB-UnOsW1Wg7S5DoZGVu0uGwlwvlYxI_NPXO5tVXy4wAj8nTbx_4GPIp0bRnkhJajIB-3bo4S3rPikTusknvVJbK-Y5Xx5n-Yyw2V1ewJ%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FUvMIQ06uST8nVYdX4u8dgREdF2tJcISTBBJ-lvlOlnf6Fu78tiIq54UktktDPuI1jZmbb5Ux8GBYT1RO72giBYtAB-UnOsW1Wg7S5DoZGVu0uGwlwvlYxI_NPXO5tVXy4wAj8nTbx_4GPIp0bRnkhJajIB-3bo4S3rPikTusknvVJbK-Y5Xx5n-Yyw2V1ewJ%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="723"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FvVS0cfPxNbzTOron4nhSaON52sb260DzusxzdApTNxXI2cpw6k7Qxl7c-9lUVmx6ysi4fxffFibTlQgXftEwNVMkC5aOeztMuQvkDIQfkWKojZEXxs0P_iRA_lDrnTbtjBL8jqlbylfgJODuP34QMWEugxsbjTN3DmSzLTN6JJoZp07NGiGXC817c8F7D2bA%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FvVS0cfPxNbzTOron4nhSaON52sb260DzusxzdApTNxXI2cpw6k7Qxl7c-9lUVmx6ysi4fxffFibTlQgXftEwNVMkC5aOeztMuQvkDIQfkWKojZEXxs0P_iRA_lDrnTbtjBL8jqlbylfgJODuP34QMWEugxsbjTN3DmSzLTN6JJoZp07NGiGXC817c8F7D2bA%3Fpurpose%3Dfullsize" alt="Image" width="1536" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FaLSgRFdW6i19WNBrgRL_1lGUWLMF0EaAfQCKtZs3yP48tPKLB9OZtCrMZBIR0p0zsgl0BznM_scZVU3LcUJkHCp8XGT8sdq7MWEEXAEEMuwj8Cr-dRCW5jYyTSVam-tEpL-dgi4mhoyWW8alch2cOlFOt0-k4HlI7EqQe3SpSwlVSCwsVLpFTd8OJCZjVLoI%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FaLSgRFdW6i19WNBrgRL_1lGUWLMF0EaAfQCKtZs3yP48tPKLB9OZtCrMZBIR0p0zsgl0BznM_scZVU3LcUJkHCp8XGT8sdq7MWEEXAEEMuwj8Cr-dRCW5jYyTSVam-tEpL-dgi4mhoyWW8alch2cOlFOt0-k4HlI7EqQe3SpSwlVSCwsVLpFTd8OJCZjVLoI%3Fpurpose%3Dfullsize" alt="Image" width="2005" height="1521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FR_wfS0hOpgnKueZkxNNrFYa1BaaFp89IstaiMAuIb9mgp1tFuiuOOi6IwqgtuosX9Xs-_UF1u7pMaUfLskKLGsl7GksU2StJM_0V9l9Ntd9QujMVYgTqvxrDKrLHWG9xkhelqGPV0AMXmB2ZyL5nazzQTRgtLajJOLiT3UuUCaYGc8c95jHh7SSgEKmf_d96%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FR_wfS0hOpgnKueZkxNNrFYa1BaaFp89IstaiMAuIb9mgp1tFuiuOOi6IwqgtuosX9Xs-_UF1u7pMaUfLskKLGsl7GksU2StJM_0V9l9Ntd9QujMVYgTqvxrDKrLHWG9xkhelqGPV0AMXmB2ZyL5nazzQTRgtLajJOLiT3UuUCaYGc8c95jHh7SSgEKmf_d96%3Fpurpose%3Dfullsize" alt="Image" width="2000" height="1332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Statistics is one of the foundations of &lt;strong&gt;data science&lt;/strong&gt;. Although data scientists work with programming languages such as Python and R, statistical methods provide the mathematical tools needed to understand patterns, compare groups, test assumptions, and determine whether observed differences are likely to be meaningful.&lt;/p&gt;

&lt;p&gt;When analyzing data, one common goal is to determine whether there is enough evidence to support a particular claim. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does a new marketing campaign increase sales?&lt;/li&gt;
&lt;li&gt;Do two groups have significantly different average incomes?&lt;/li&gt;
&lt;li&gt;Is there a relationship between two variables?&lt;/li&gt;
&lt;li&gt;Does a treatment produce a different outcome?&lt;/li&gt;
&lt;li&gt;Are several groups significantly different from one another?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Statistical tests help answer these questions. Two major categories of statistical tests are &lt;strong&gt;parametric tests&lt;/strong&gt; and &lt;strong&gt;non-parametric tests&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The main difference is that parametric tests generally make stronger assumptions about the underlying population distribution, while non-parametric tests generally require fewer distributional assumptions. IBM describes non-parametric tests as methods that make minimal assumptions about the underlying distribution of the data. (&lt;a href="https://www.ibm.com/docs/en/spss-statistics/32.0.0?topic=features-nonparametric-tests&amp;amp;utm_source=chatgpt.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Understanding when to use each type of test is an important skill for anyone working in data science.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. What Are Statistical Tests?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fallz_uDK24Z_5u3LJbGCk-xtm7u1bDhrEvL4vjDF4bK8lFaH8JHPWDLlgsT3bb4cS8lWZkcMNnv0Xklov8CmRgZSYbBk67UtJSkefV9UYyhNQ0WFzBex9SpPMaEmBQX9RfRmcb9g5BgKuN2_ym4zzR2Pl0A0cw52aF5ACcAEeDe0r_TZ0S06JZKMX5uXhntl%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fallz_uDK24Z_5u3LJbGCk-xtm7u1bDhrEvL4vjDF4bK8lFaH8JHPWDLlgsT3bb4cS8lWZkcMNnv0Xklov8CmRgZSYbBk67UtJSkefV9UYyhNQ0WFzBex9SpPMaEmBQX9RfRmcb9g5BgKuN2_ym4zzR2Pl0A0cw52aF5ACcAEeDe0r_TZ0S06JZKMX5uXhntl%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="1536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FXxycVn-P1FrUfEEBJoUb9pNOzo47l77Mgs9vL9urwsxf2pYKNTMvt_P79PDs8Da0UjlSewCnockzJ-7pUxC3ODjUcumLSyJ2NC1OX8rbVUD-Vnn1vSTd9OjKvY567lyNxpPnsFoHW52vO-vhbg2s-lMhNQOHukiOKA54o951GlMMzBOLQNQ5VYpGwpAbADBF%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FXxycVn-P1FrUfEEBJoUb9pNOzo47l77Mgs9vL9urwsxf2pYKNTMvt_P79PDs8Da0UjlSewCnockzJ-7pUxC3ODjUcumLSyJ2NC1OX8rbVUD-Vnn1vSTd9OjKvY567lyNxpPnsFoHW52vO-vhbg2s-lMhNQOHukiOKA54o951GlMMzBOLQNQ5VYpGwpAbADBF%3Fpurpose%3Dfullsize" alt="Image" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FAxjB9hshl-uX7iO_446uRyHurVt8InjR1JNRG8GUsSD9hNGvxX692Lcw2Gb2y-vDoJ8-vh4CKgj6QGZonD5iey_1RQsj1dE56O7KS6FvKZ-ALD6Y4BYzUDlwEKsjOAeX7hdCdI-Wqw1Cti1Yj1MHBneG3XM9qUKNEcMjNJlRFSbq555yT7-8ar_TQfBQ4VQ-%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FAxjB9hshl-uX7iO_446uRyHurVt8InjR1JNRG8GUsSD9hNGvxX692Lcw2Gb2y-vDoJ8-vh4CKgj6QGZonD5iey_1RQsj1dE56O7KS6FvKZ-ALD6Y4BYzUDlwEKsjOAeX7hdCdI-Wqw1Cti1Yj1MHBneG3XM9qUKNEcMjNJlRFSbq555yT7-8ar_TQfBQ4VQ-%3Fpurpose%3Dfullsize" alt="Image" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FMX9PA_NwVD6ayH_Pd4S6PgEUpFUS4VBvolZRWTFNDlNCbTFf4dADDzNijDr09NsXeMAe0qnzq9wpdQt61z8BIBGytOqEaew3DdVSfNopl8k9bLHMNvMv43bow6qrj2_gBmmkQ37voVYrzHMFIfORveNFQzl2rKGCZ6eVh23RIuIDjrS1Km1kyt78CC6dM1ME%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FMX9PA_NwVD6ayH_Pd4S6PgEUpFUS4VBvolZRWTFNDlNCbTFf4dADDzNijDr09NsXeMAe0qnzq9wpdQt61z8BIBGytOqEaew3DdVSfNopl8k9bLHMNvMv43bow6qrj2_gBmmkQ37voVYrzHMFIfORveNFQzl2rKGCZ6eVh23RIuIDjrS1Km1kyt78CC6dM1ME%3Fpurpose%3Dfullsize" alt="Image" width="1600" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FQ_w94Z_hCN--LoJ3PbbKFSWorGCohAsBZKkbRAJIG7fTSqXSrvjm-WllczZsiNqPkJTNed5WPpKFZX8iSPajv6vvZHha7NbHF9coYGU4bZ5gSRLgYkw-Vg2cm_oI-DIhZvZSBotLH5z6-VLMKmfj9I2boEYS4sj25j-fmX9g5w3lr23HiNef53KMwt5dc3AR%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FQ_w94Z_hCN--LoJ3PbbKFSWorGCohAsBZKkbRAJIG7fTSqXSrvjm-WllczZsiNqPkJTNed5WPpKFZX8iSPajv6vvZHha7NbHF9coYGU4bZ5gSRLgYkw-Vg2cm_oI-DIhZvZSBotLH5z6-VLMKmfj9I2boEYS4sj25j-fmX9g5w3lr23HiNef53KMwt5dc3AR%3Fpurpose%3Dfullsize" alt="Image" width="600" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;statistical test&lt;/strong&gt; is a mathematical procedure used to evaluate evidence in a sample and make an inference about a population.&lt;/p&gt;

&lt;p&gt;Suppose a company claims that its average customer satisfaction score is &lt;strong&gt;80&lt;/strong&gt;. You collect a sample of customers and calculate an average score of 84.&lt;/p&gt;

&lt;p&gt;The difference between 80 and 84 might be meaningful—or it might simply be the result of random sampling variation.&lt;/p&gt;

&lt;p&gt;A statistical test helps determine whether the evidence is strong enough to reject a &lt;strong&gt;null hypothesis&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Null hypothesis
&lt;/h3&gt;

&lt;p&gt;The null hypothesis, commonly represented as &lt;strong&gt;H₀&lt;/strong&gt;, usually states that there is no meaningful difference, relationship, or effect.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;H₀: There is no difference in the average satisfaction scores between the two groups.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Alternative hypothesis
&lt;/h3&gt;

&lt;p&gt;The alternative hypothesis, represented as &lt;strong&gt;H₁&lt;/strong&gt; or &lt;strong&gt;Hₐ&lt;/strong&gt;, represents the possibility that a difference or relationship exists.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;H₁: There is a difference in the average satisfaction scores between the two groups.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Statistical testing then produces a &lt;strong&gt;test statistic&lt;/strong&gt; and usually a &lt;strong&gt;p-value&lt;/strong&gt;, which can be used as evidence when evaluating the null hypothesis.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. Parametric Tests
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FQGTSy-Xgq0emSuD11e8fo_P93jgKgfsCDqZVDf3MDzo__h9JHsvzjQLNE23FEHuLrNpP2WxT_tlWDaO4Ic2sZ3X2DuNjjSikKGcZgyJUS9pANHUOl8C6ECdAP04u850QuJPZqUPwZCS_k26e7l2BMMJpLn8IyZSFYe-eOOxUtHX3SBvXCtaRymCqQ8N0jrW7%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FQGTSy-Xgq0emSuD11e8fo_P93jgKgfsCDqZVDf3MDzo__h9JHsvzjQLNE23FEHuLrNpP2WxT_tlWDaO4Ic2sZ3X2DuNjjSikKGcZgyJUS9pANHUOl8C6ECdAP04u850QuJPZqUPwZCS_k26e7l2BMMJpLn8IyZSFYe-eOOxUtHX3SBvXCtaRymCqQ8N0jrW7%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FJ-0sktC-SWvRNtXzTtTdigvYZ7PsGjlPjnz2VIMwcYTCVVnIxnbiYosi_rgcvx-4R-UImFm9UqtktnmViaNf1ol9SxBtXBmQN0VyHdDmahcA_yC-38n7fiYVICvHhjV2ekAujWhxgwt-SXwK5EHhlrMjsDek3Hc9qJmfBmE1LUt6xohQWbrpSIcPokLgeDsG%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FJ-0sktC-SWvRNtXzTtTdigvYZ7PsGjlPjnz2VIMwcYTCVVnIxnbiYosi_rgcvx-4R-UImFm9UqtktnmViaNf1ol9SxBtXBmQN0VyHdDmahcA_yC-38n7fiYVICvHhjV2ekAujWhxgwt-SXwK5EHhlrMjsDek3Hc9qJmfBmE1LUt6xohQWbrpSIcPokLgeDsG%3Fpurpose%3Dfullsize" alt="Image" width="2048" height="1152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FRUsG-yIehr2_YCl6NtbeyeBPFBvOg7jxOurMtTuXFmGDyXmB36Gz3D20mek2g5b1gtNwAwPHv2xZAIqf5E307G411oDgkES_rwB9bBxydMogjXYHy2ZLjmsz2X3cH7Frj7Gp-jzaBiYyiWZW07U9aZX2fkNOizOQi4Rz1W8tQvQzTMqbkDUD_kQeMuunqWbM%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FRUsG-yIehr2_YCl6NtbeyeBPFBvOg7jxOurMtTuXFmGDyXmB36Gz3D20mek2g5b1gtNwAwPHv2xZAIqf5E307G411oDgkES_rwB9bBxydMogjXYHy2ZLjmsz2X3cH7Frj7Gp-jzaBiYyiWZW07U9aZX2fkNOizOQi4Rz1W8tQvQzTMqbkDUD_kQeMuunqWbM%3Fpurpose%3Dfullsize" alt="Image" width="680" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FvVS0cfPxNbzTOron4nhSaON52sb260DzusxzdApTNxXI2cpw6k7Qxl7c-9lUVmx6ysi4fxffFibTlQgXftEwNVMkC5aOeztMuQvkDIQfkWKojZEXxs0P_iRA_lDrnTbtjBL8jqlbylfgJODuP34QMWEugxsbjTN3DmSzLTN6JJoZp07NGiGXC817c8F7D2bA%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FvVS0cfPxNbzTOron4nhSaON52sb260DzusxzdApTNxXI2cpw6k7Qxl7c-9lUVmx6ysi4fxffFibTlQgXftEwNVMkC5aOeztMuQvkDIQfkWKojZEXxs0P_iRA_lDrnTbtjBL8jqlbylfgJODuP34QMWEugxsbjTN3DmSzLTN6JJoZp07NGiGXC817c8F7D2bA%3Fpurpose%3Dfullsize" alt="Image" width="1536" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FLSme60fjZnDe7CaA2SY-ppJdBRFxr_cMT15lRPrh3LJTdS7n-6Wrrc-XRnPN8X6punA79Q83HWoeSivEQ9-I8uxc-_r49GD01Fo2dbR2dQOM414zEcCOnue0x9g67CT2gqqr-DLTbP2mpqzVlbn3szsdkxctWTQ_j1ezlqj38qrPB04liNkM6WIpBXlUDOsS%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FLSme60fjZnDe7CaA2SY-ppJdBRFxr_cMT15lRPrh3LJTdS7n-6Wrrc-XRnPN8X6punA79Q83HWoeSivEQ9-I8uxc-_r49GD01Fo2dbR2dQOM414zEcCOnue0x9g67CT2gqqr-DLTbP2mpqzVlbn3szsdkxctWTQ_j1ezlqj38qrPB04liNkM6WIpBXlUDOsS%3Fpurpose%3Dfullsize" alt="Image" width="1195" height="811"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parametric tests&lt;/strong&gt; are statistical tests that make assumptions about the parameters or distribution of the population being studied.&lt;/p&gt;

&lt;p&gt;A common assumption is that the data—or the relevant model residuals—follow a particular distribution, often a &lt;strong&gt;normal distribution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Parametric tests are often powerful when their assumptions are reasonably satisfied.&lt;/p&gt;

&lt;p&gt;Common parametric tests include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;One-sample t-test&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Independent-samples t-test&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Paired-samples t-test&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ANOVA&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pearson correlation&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The exact assumptions depend on the particular test. Therefore, it is not enough to simply label a dataset "parametric" or "non-parametric"; the suitability of a test depends on the data, study design, and assumptions being evaluated.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. The t-Test
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F-coj_ymMXWeRXdfFjRHSAcR4WZhnWmlXISQrZVUlua631Xw0BsoAkl56GBPPC_0hTCy7iJA_HDyKPZY0_j_Kgiv3XcmlpVGhwVrWpsL0fkRYiU7S6coD930dWbqVmtqmcgOGWdu6W1XQhYx-GQUYGOf_YBMk0-IqBtE0qza8FJqLvYsM5Ev3-XOYGllH5xmC%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F-coj_ymMXWeRXdfFjRHSAcR4WZhnWmlXISQrZVUlua631Xw0BsoAkl56GBPPC_0hTCy7iJA_HDyKPZY0_j_Kgiv3XcmlpVGhwVrWpsL0fkRYiU7S6coD930dWbqVmtqmcgOGWdu6W1XQhYx-GQUYGOf_YBMk0-IqBtE0qza8FJqLvYsM5Ev3-XOYGllH5xmC%3Fpurpose%3Dfullsize" alt="Image" width="1600" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Ft-pOTcVhGIh_ZLaU-NwVoDBZQwOTwZYPN_iJgec_jNHWn2S67s-whPGHPS1So0dONCDdbtxrX6wHjxzKyLK7QO9jrC5sDesKlKE8XsK1Xlq7YttiM8VnfYCq4-rWavOjV6VkB3e9Z0e-WLe9dDvxmYWC9nin6BFTXqUPk3_HMprotWHVCqAUheFTHvYS_YbK%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Ft-pOTcVhGIh_ZLaU-NwVoDBZQwOTwZYPN_iJgec_jNHWn2S67s-whPGHPS1So0dONCDdbtxrX6wHjxzKyLK7QO9jrC5sDesKlKE8XsK1Xlq7YttiM8VnfYCq4-rWavOjV6VkB3e9Z0e-WLe9dDvxmYWC9nin6BFTXqUPk3_HMprotWHVCqAUheFTHvYS_YbK%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FPBQtQEUKgKz5YN21j-7nBNEKMDPyb6eFis0EijXpsQD5QdMTyovyY9zhmF3D6GnIgwQn_d32QDKP4y1edSCnkrxld57iwnRHpejODNidjoT-EZB1GFwmq2bJYZCIC34ItCuQMiMkrECRuqsOk6UHesvxD52G-T-IKsOpshXRFVxXPtgRU409V5Zajh9gzSG8%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FPBQtQEUKgKz5YN21j-7nBNEKMDPyb6eFis0EijXpsQD5QdMTyovyY9zhmF3D6GnIgwQn_d32QDKP4y1edSCnkrxld57iwnRHpejODNidjoT-EZB1GFwmq2bJYZCIC34ItCuQMiMkrECRuqsOk6UHesvxD52G-T-IKsOpshXRFVxXPtgRU409V5Zajh9gzSG8%3Fpurpose%3Dfullsize" alt="Image" width="1781" height="853"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FP-v5sfVc-82UH2K6pjsmA7Bn4g3fuHOCtx7m8DHlntEa4DhzujNUAnmRT5D019oAkKe2m4FguFM0N2014WagxuxacI9PKcn3tCJPVrMchzQHJN8IwLELPRtFncE5rJcSHh014wB-Dj7wV8k_xt7sfFRTBA0B8MbTs52rrDTALdRPShISm5j4Nclj5XcsBH8w%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FP-v5sfVc-82UH2K6pjsmA7Bn4g3fuHOCtx7m8DHlntEa4DhzujNUAnmRT5D019oAkKe2m4FguFM0N2014WagxuxacI9PKcn3tCJPVrMchzQHJN8IwLELPRtFncE5rJcSHh014wB-Dj7wV8k_xt7sfFRTBA0B8MbTs52rrDTALdRPShISm5j4Nclj5XcsBH8w%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FrOEp5nqA2F640WOTyoytV65rTU1ZfvKSnj4LoKInwOtCSR346h3Xa2LJ5765UzcUEHYkhVfVr5_cVelUWHdwsFYbu2wZciDUlR6A3UlxHTWXJzV3dm0zQI2JKwAMXl2zhFx1i1aKo9TqZxOq_QLDKUeTNhuZcZqnw0KhfHwoSGLyUwT_G9PE3IRVAeff9_ix%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FrOEp5nqA2F640WOTyoytV65rTU1ZfvKSnj4LoKInwOtCSR346h3Xa2LJ5765UzcUEHYkhVfVr5_cVelUWHdwsFYbu2wZciDUlR6A3UlxHTWXJzV3dm0zQI2JKwAMXl2zhFx1i1aKo9TqZxOq_QLDKUeTNhuZcZqnw0KhfHwoSGLyUwT_G9PE3IRVAeff9_ix%3Fpurpose%3Dfullsize" alt="Image" width="1536" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FnzEes7f7UfSbbahbw7mH3ITdMlIsJYCRblWVEGFWwXTkuYiihhXXhKxcMXYec4SAGBMae2mEmUfICWVsgmGNZBG0ecevqFAyFea6mp9Ek-oOe8h4YuAbMeLdzsZgHIG4jVjjju5eBruJ_Jh7djgX5gE8pJMmFd6Hb0-dbw7tI2VlU5BARJ2iH5G6l1oyac3q%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FnzEes7f7UfSbbahbw7mH3ITdMlIsJYCRblWVEGFWwXTkuYiihhXXhKxcMXYec4SAGBMae2mEmUfICWVsgmGNZBG0ecevqFAyFea6mp9Ek-oOe8h4YuAbMeLdzsZgHIG4jVjjju5eBruJ_Jh7djgX5gE8pJMmFd6Hb0-dbw7tI2VlU5BARJ2iH5G6l1oyac3q%3Fpurpose%3Dfullsize" alt="Image" width="1400" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;t-test&lt;/strong&gt; is one of the most commonly used parametric tests.&lt;/p&gt;

&lt;p&gt;It is generally used when comparing means.&lt;/p&gt;

&lt;p&gt;There are several common types.&lt;/p&gt;

&lt;h3&gt;
  
  
  One-Sample t-Test
&lt;/h3&gt;

&lt;p&gt;A one-sample t-test compares the mean of a sample with a specified value.&lt;/p&gt;

&lt;p&gt;For example, suppose a company believes its employees work an average of 40 hours per week.&lt;/p&gt;

&lt;p&gt;You could test whether the average working time in your sample differs from 40 hours.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H₀: μ = 40
H₁: μ ≠ 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Independent-Samples t-Test
&lt;/h3&gt;

&lt;p&gt;An independent-samples t-test compares two independent groups.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Is the average salary of Group A different from the average salary of Group B?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Paired-Samples t-Test
&lt;/h3&gt;

&lt;p&gt;A paired t-test is used when observations are naturally paired, such as measurements taken from the same subjects before and after an intervention.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Did the average test score change after students completed a training program?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The important point is that the observations are paired rather than treated as two unrelated groups.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. ANOVA
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FlAXvy0nRMULe7xhV_VLiiqFzvSdgos5vNpQ5vmsPk_JcwqBAE3GZujWKsGBJybz8CRbXWBBlDT3wV7PCCtzmvqHfygNlrR6BgQa1jZF6JojtkHO4_Zz25bvFnJYZL0mQSigxcpZ9kySgaIWhCeOw43UNwOHne_10JpDgmNuQ_cq8KMi8qhuaGzUsiqdTDLYH%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FlAXvy0nRMULe7xhV_VLiiqFzvSdgos5vNpQ5vmsPk_JcwqBAE3GZujWKsGBJybz8CRbXWBBlDT3wV7PCCtzmvqHfygNlrR6BgQa1jZF6JojtkHO4_Zz25bvFnJYZL0mQSigxcpZ9kySgaIWhCeOw43UNwOHne_10JpDgmNuQ_cq8KMi8qhuaGzUsiqdTDLYH%3Fpurpose%3Dfullsize" alt="Image" width="896" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fmzkg7w5ussJiHS24loVK0ZWEeG334pdKZhewv_HrpHRRK6lgeJkgquoNcePMDjG6E2X3g9GhYBcvD7_HZMzqE23x8uE9vARlNRb5G_KFsJaU_HcZ95FcZhCoBhV0Pq2jPIX9IzRYF2HsFLsVdw4IBBPH1dD-qemPLzpayVizRSNHFTtVeME9xvC1JX9_cGip%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fmzkg7w5ussJiHS24loVK0ZWEeG334pdKZhewv_HrpHRRK6lgeJkgquoNcePMDjG6E2X3g9GhYBcvD7_HZMzqE23x8uE9vARlNRb5G_KFsJaU_HcZ95FcZhCoBhV0Pq2jPIX9IzRYF2HsFLsVdw4IBBPH1dD-qemPLzpayVizRSNHFTtVeME9xvC1JX9_cGip%3Fpurpose%3Dfullsize" alt="Image" width="720" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FfM-v20zCC5jJQQUEEcqPuTI1TMGDPXw61BWOMnKyKFLepf4nTARYHpb9-491xWFcAFTARw61_itZnjQ5MkZGXu1Hsd1Z6XmFrsBSopDE-oXXmUCpJQfr8i8VO5JWZMoECMZa96athxc7mCW-Esf391mgAu7lfG7Nbdcogrt23yTmvTNQQx1UfPftdTC4IDjm%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FfM-v20zCC5jJQQUEEcqPuTI1TMGDPXw61BWOMnKyKFLepf4nTARYHpb9-491xWFcAFTARw61_itZnjQ5MkZGXu1Hsd1Z6XmFrsBSopDE-oXXmUCpJQfr8i8VO5JWZMoECMZa96athxc7mCW-Esf391mgAu7lfG7Nbdcogrt23yTmvTNQQx1UfPftdTC4IDjm%3Fpurpose%3Dfullsize" alt="Image" width="945" height="784"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FwBHaZRWeOMLjVc01dntPvt9zXJOMeYROTOi9McHE--xD8b6zMiQ0W8466Tzmr2tVVhS4IohTh3238R6-MrdQfINJ539KxmS9KOCyuSUxkLeYjeqIzxeOf2G8tUeVOggtOlJvTVFuWwOzbo8gBTWLe48fHHse9xpJlLgBr0hjPdZT0TUZCekDk4-7hUrTb95z%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FwBHaZRWeOMLjVc01dntPvt9zXJOMeYROTOi9McHE--xD8b6zMiQ0W8466Tzmr2tVVhS4IohTh3238R6-MrdQfINJ539KxmS9KOCyuSUxkLeYjeqIzxeOf2G8tUeVOggtOlJvTVFuWwOzbo8gBTWLe48fHHse9xpJlLgBr0hjPdZT0TUZCekDk4-7hUrTb95z%3Fpurpose%3Dfullsize" alt="Image" width="1280" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F5X-CtYSSlT64pV2ivr4g0IStXqWOGhZysmP6ML-YNsIXBqguU5RFThVMfAKpmrJrlfmEFX24hwZy18LOXpAXhfiYEq5_JlPa9gX9y4UiGkf7YWXxMIGFA9OkmbmcFeWk2-aex7PGg-UwoyA3QDYoWdeNG3F2Qy2SLNAETKgBqsQynJXMUjIIUxUknh90mM0f%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F5X-CtYSSlT64pV2ivr4g0IStXqWOGhZysmP6ML-YNsIXBqguU5RFThVMfAKpmrJrlfmEFX24hwZy18LOXpAXhfiYEq5_JlPa9gX9y4UiGkf7YWXxMIGFA9OkmbmcFeWk2-aex7PGg-UwoyA3QDYoWdeNG3F2Qy2SLNAETKgBqsQynJXMUjIIUxUknh90mM0f%3Fpurpose%3Dfullsize" alt="Image" width="860" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ANOVA&lt;/strong&gt;, or &lt;strong&gt;Analysis of Variance&lt;/strong&gt;, is used when comparing the means of multiple groups.&lt;/p&gt;

&lt;p&gt;For example, imagine that a company wants to compare the average sales generated by three different marketing strategies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Strategy A → Average sales
Strategy B → Average sales
Strategy C → Average sales
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of conducting many separate t-tests, a one-way ANOVA can be used to test whether there is evidence that the group means are not all equal.&lt;/p&gt;

&lt;p&gt;The basic idea is to compare:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Between-group variation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;with&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Within-group variation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;genui{"learning_viz":{"type_id":"ANOVA_DECOMPOSITION"}}&lt;/p&gt;

&lt;p&gt;A large ratio of between-group variation to within-group variation provides stronger evidence against the hypothesis that all group means are equal.&lt;/p&gt;

&lt;p&gt;However, ANOVA tells you that a difference exists somewhere among the groups; it does not automatically identify which specific groups differ. Follow-up comparisons may be required.&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Non-Parametric Tests
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FQQdvLle3oDZQx-jdYxrjcCNH8XYykfNAHLYsvcOdgfdQ9W3bknETdL4pvu2_pKHA7piflzFginHm9R3vYXj4HKjhAWhjuQb-lDFi3wtf4EJpzXt3jH7MmZICmn3gLLtByOL3Uo26fo4W67HzOYpjoZ2TWGBiD5IagNtnWlYM_DTCZ_Vitj_jArnSHBbDS_YE%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FQQdvLle3oDZQx-jdYxrjcCNH8XYykfNAHLYsvcOdgfdQ9W3bknETdL4pvu2_pKHA7piflzFginHm9R3vYXj4HKjhAWhjuQb-lDFi3wtf4EJpzXt3jH7MmZICmn3gLLtByOL3Uo26fo4W67HzOYpjoZ2TWGBiD5IagNtnWlYM_DTCZ_Vitj_jArnSHBbDS_YE%3Fpurpose%3Dfullsize" alt="Image" width="612" height="610"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fbl3aXIrY3iAa_Tuopfc8NYXHuov0daIn53GH7NohSADMSz4yftbK9EHGUbV_QVFM1bgN9nUtfO4HT3aMzMTOZfr9cyqGzFoW2L5eyVSskRrvQK6HpLO-wQMk5LAPxMoIDTZEEwALYnKIMfyMH2NcSK7SiDoLFJWnnNyP37m2jo0mzuq6tBrmdr-mNGV0mu00%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fbl3aXIrY3iAa_Tuopfc8NYXHuov0daIn53GH7NohSADMSz4yftbK9EHGUbV_QVFM1bgN9nUtfO4HT3aMzMTOZfr9cyqGzFoW2L5eyVSskRrvQK6HpLO-wQMk5LAPxMoIDTZEEwALYnKIMfyMH2NcSK7SiDoLFJWnnNyP37m2jo0mzuq6tBrmdr-mNGV0mu00%3Fpurpose%3Dfullsize" alt="Image" width="2048" height="1536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FvVS0cfPxNbzTOron4nhSaON52sb260DzusxzdApTNxXI2cpw6k7Qxl7c-9lUVmx6ysi4fxffFibTlQgXftEwNVMkC5aOeztMuQvkDIQfkWKojZEXxs0P_iRA_lDrnTbtjBL8jqlbylfgJODuP34QMWEugxsbjTN3DmSzLTN6JJoZp07NGiGXC817c8F7D2bA%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FvVS0cfPxNbzTOron4nhSaON52sb260DzusxzdApTNxXI2cpw6k7Qxl7c-9lUVmx6ysi4fxffFibTlQgXftEwNVMkC5aOeztMuQvkDIQfkWKojZEXxs0P_iRA_lDrnTbtjBL8jqlbylfgJODuP34QMWEugxsbjTN3DmSzLTN6JJoZp07NGiGXC817c8F7D2bA%3Fpurpose%3Dfullsize" alt="Image" width="1536" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FBNeOmnbz3vs1xoy30UwTF8kqQW-LjkeIQsv6ZhwVQpW--mecBIQxmj_xvkBDarEQ5v05gNMETCRfr91iicV98Qdkyw_9gOvZSEY1qs3xxVj_AUqzg39e0f0woqSJiHQ8SFk1xj2H3cZx_nIMXPdOi9yxDH-O1DQb7k5_bHM332TsYbgICiPD5aEXVodS04Xc%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FBNeOmnbz3vs1xoy30UwTF8kqQW-LjkeIQsv6ZhwVQpW--mecBIQxmj_xvkBDarEQ5v05gNMETCRfr91iicV98Qdkyw_9gOvZSEY1qs3xxVj_AUqzg39e0f0woqSJiHQ8SFk1xj2H3cZx_nIMXPdOi9yxDH-O1DQb7k5_bHM332TsYbgICiPD5aEXVodS04Xc%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FCHLiwu_FRqPH1_aIqecmc6BhdfKR0u29OoT4dX5xOl0B5de_52IilU96-KrMw_JowmjKw59GDbSA1kDIz7raVegzwP2efh-DP8oxKqf4N-qGORKnVeGbWaTVyk9da7VM_aflec4own1me8pdO0Gcw1dHuBrhpDmBUeuz2ka_l5W1TAjROxWjISv3ve5T_CLS%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FCHLiwu_FRqPH1_aIqecmc6BhdfKR0u29OoT4dX5xOl0B5de_52IilU96-KrMw_JowmjKw59GDbSA1kDIz7raVegzwP2efh-DP8oxKqf4N-qGORKnVeGbWaTVyk9da7VM_aflec4own1me8pdO0Gcw1dHuBrhpDmBUeuz2ka_l5W1TAjROxWjISv3ve5T_CLS%3Fpurpose%3Dfullsize" alt="Image" width="1056" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F9kcGSAQMcMoR9CAC7j71nKx-zH1dI_u69IV-JaRLfmWgry9DmYsMt0CcJFEV4NtOT8dmsTJKstcDG2-JbK8ur3v0aH5Az__691bqZZy_c5JhKtLnLHTJYomn9zL2W-l1nwR2lZU6mfqevoU1kREVCdDLsD3rTx7isEZLSYFLEAGapTetr5eu5MvExmUDNk9Z%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F9kcGSAQMcMoR9CAC7j71nKx-zH1dI_u69IV-JaRLfmWgry9DmYsMt0CcJFEV4NtOT8dmsTJKstcDG2-JbK8ur3v0aH5Az__691bqZZy_c5JhKtLnLHTJYomn9zL2W-l1nwR2lZU6mfqevoU1kREVCdDLsD3rTx7isEZLSYFLEAGapTetr5eu5MvExmUDNk9Z%3Fpurpose%3Dfullsize" alt="Image" width="960" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-parametric tests&lt;/strong&gt; are statistical procedures that generally make fewer assumptions about the underlying distribution of the data.&lt;/p&gt;

&lt;p&gt;This can be useful when data are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Highly skewed&lt;/li&gt;
&lt;li&gt;Ordinal&lt;/li&gt;
&lt;li&gt;Affected by extreme outliers&lt;/li&gt;
&lt;li&gt;Not reasonably modeled by the assumptions of a parametric test&lt;/li&gt;
&lt;li&gt;Based on small samples where distributional assumptions are questionable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;IBM notes that non-parametric tests make minimal assumptions about the underlying distribution and can be organized according to whether they involve one sample, related samples, or independent samples. (&lt;a href="https://www.ibm.com/docs/en/spss-statistics/32.0.0?topic=features-nonparametric-tests&amp;amp;utm_source=chatgpt.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Common non-parametric tests include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mann–Whitney U test&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Wilcoxon signed-rank test&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kruskal–Wallis H test&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spearman rank correlation&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chi-square tests&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  6. Mann–Whitney U Test
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FN2llD4uknpZlPf9S2tZKgfSHZz_GpPm1_jYNoLx9Hf60pdGjGuLj7BIkSdORdU_Vd31-pZxhmdeOrtrWma-rKK4kdZ-nH77aCPN5R1kV6MqpkwE5Hkc4NUsYYiopSic13yi_mA0giLiVOSbAqRedo2vxbfg_aeHWT8aO3GKNwxXK5xvQNNh431fhxRkWbDdt%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FN2llD4uknpZlPf9S2tZKgfSHZz_GpPm1_jYNoLx9Hf60pdGjGuLj7BIkSdORdU_Vd31-pZxhmdeOrtrWma-rKK4kdZ-nH77aCPN5R1kV6MqpkwE5Hkc4NUsYYiopSic13yi_mA0giLiVOSbAqRedo2vxbfg_aeHWT8aO3GKNwxXK5xvQNNh431fhxRkWbDdt%3Fpurpose%3Dfullsize" alt="Image" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FafQzRMTnTRPtQiC9NTJHQuFUmeFjsIhqnvZLVMzzSaRIM6i-KcyTCu402wmgft7Z6Hti2yRtSRjk1UoCT3fPE80HMH4EysSzRhdhjDHcbkB-UpxWOHoGDO-_ZL0KfH6xVUFj_GPcEtMlNKdG3Zl0_U9uys1GTmqqzLpVzoL9KMBQxlCEZ9l4zE2kS_oeseoa%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FafQzRMTnTRPtQiC9NTJHQuFUmeFjsIhqnvZLVMzzSaRIM6i-KcyTCu402wmgft7Z6Hti2yRtSRjk1UoCT3fPE80HMH4EysSzRhdhjDHcbkB-UpxWOHoGDO-_ZL0KfH6xVUFj_GPcEtMlNKdG3Zl0_U9uys1GTmqqzLpVzoL9KMBQxlCEZ9l4zE2kS_oeseoa%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FrqYPN8TxX2aycpspDgHDy3POnxTcDMsyMQCbdWQR3io3PsMQfMaB3WzkTmezEQv3ZgdXcKepQJDs1ZUJTjmfnTv7ttYodXSw7fIX3JI34fTy_kv0DJX7ib3UIMNHzxZxyDUq9PWQQDdIIuT3z2HXdD2pTWcs71IIUWUT7id5wf0Y0eFwkpnZIvzcFxQ__yzE%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FrqYPN8TxX2aycpspDgHDy3POnxTcDMsyMQCbdWQR3io3PsMQfMaB3WzkTmezEQv3ZgdXcKepQJDs1ZUJTjmfnTv7ttYodXSw7fIX3JI34fTy_kv0DJX7ib3UIMNHzxZxyDUq9PWQQDdIIuT3z2HXdD2pTWcs71IIUWUT7id5wf0Y0eFwkpnZIvzcFxQ__yzE%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FNL1byCOVbkP-qPVjDKAtwJWqw98PA6ClsL0BntlLBiADqheNC5oQqyq59Rr75GzY6nZETP4DnQgo0G6PChDHeIr53EzkOnNN6wS6_3q5do6f2iF4LcS3cXOPXnrqKxktDVw3atx3IjPNzm4g5Se_eH0uTS28Oomd58ff3Dl0gM6JjC3PLHVEPftl_-o0jCFG%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FNL1byCOVbkP-qPVjDKAtwJWqw98PA6ClsL0BntlLBiADqheNC5oQqyq59Rr75GzY6nZETP4DnQgo0G6PChDHeIr53EzkOnNN6wS6_3q5do6f2iF4LcS3cXOPXnrqKxktDVw3atx3IjPNzm4g5Se_eH0uTS28Oomd58ff3Dl0gM6JjC3PLHVEPftl_-o0jCFG%3Fpurpose%3Dfullsize" alt="Image" width="2048" height="1152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FxoEXUy4JHajVngVBMNZM9PZWldgofBYR38gzG-vdvi14Hubktnf2vFUptMtLPBy9iIEzXJmng54LI20TSS_Q-rC_wNK2wd7wn3d7H_MLgYviTnbnfLx_BS5jDVgsjjcCXmglxmtOZaqLxj4uwP0eU5zjbOtlEsRfUgwaQCamO4qx6OciQkD8APjLchZ0nOAi%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FxoEXUy4JHajVngVBMNZM9PZWldgofBYR38gzG-vdvi14Hubktnf2vFUptMtLPBy9iIEzXJmng54LI20TSS_Q-rC_wNK2wd7wn3d7H_MLgYviTnbnfLx_BS5jDVgsjjcCXmglxmtOZaqLxj4uwP0eU5zjbOtlEsRfUgwaQCamO4qx6OciQkD8APjLchZ0nOAi%3Fpurpose%3Dfullsize" alt="Image" width="894" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Mann–Whitney U test&lt;/strong&gt; is commonly used to compare two independent groups when a t-test may not be appropriate.&lt;/p&gt;

&lt;p&gt;For example, suppose we want to compare customer spending between two groups:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Group A → 100, 120, 150, 170, 200
Group B → 80, 90, 110, 130, 140
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the data are strongly skewed or otherwise do not satisfy the assumptions needed for a conventional t-test, a Mann–Whitney test may be considered.&lt;/p&gt;

&lt;p&gt;Rather than relying directly on the raw values in the same way as a t-test, the Mann–Whitney procedure works with the &lt;strong&gt;ranks&lt;/strong&gt; of observations.&lt;/p&gt;




&lt;h1&gt;
  
  
  7. Wilcoxon Signed-Rank Test
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Wilcoxon signed-rank test&lt;/strong&gt; is commonly used as a non-parametric alternative for paired data.&lt;/p&gt;

&lt;p&gt;For example, suppose you measure employees' productivity before and after training:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Employee&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;60&lt;/td&gt;
&lt;td&gt;65&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;72&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;55&lt;/td&gt;
&lt;td&gt;61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D&lt;/td&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;td&gt;81&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Instead of using a paired t-test, you could consider a Wilcoxon signed-rank test when the assumptions for the paired t-test are not appropriate.&lt;/p&gt;

&lt;p&gt;IBM lists the Wilcoxon signed-rank test among its one-sample non-parametric procedures for continuous and ordinal fields. (&lt;a href="https://www.ibm.com/docs/en/spss-statistics/32.0.0?topic=tests-choose-one-sample-nonparametric&amp;amp;utm_source=chatgpt.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;)&lt;/p&gt;




&lt;h1&gt;
  
  
  8. Kruskal–Wallis Test
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FUD8OTgxrfXeedeVSVrn8VWIKwwxPeGWZ6bSIiDfOnwbEHy6ZCNBpnhFcS0ZbkFIHBXTxFx-MBeoP34pGjkzALojTRJE7cTbZ7pNRmxqnsN46s7Vg0woVuyBOTdw9Q8kRTWC4as98Qtfhkn8_sUhoe7AXp0jmEOYaqwNpLHr_weHR8fA4tdUMp_5NjVry2Ilr%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FUD8OTgxrfXeedeVSVrn8VWIKwwxPeGWZ6bSIiDfOnwbEHy6ZCNBpnhFcS0ZbkFIHBXTxFx-MBeoP34pGjkzALojTRJE7cTbZ7pNRmxqnsN46s7Vg0woVuyBOTdw9Q8kRTWC4as98Qtfhkn8_sUhoe7AXp0jmEOYaqwNpLHr_weHR8fA4tdUMp_5NjVry2Ilr%3Fpurpose%3Dfullsize" alt="Image" width="681" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FSNPVdeNIy_0Pw_eNLKEGoZc8Nv3jMH45zb13ZpFoOoyw-eVpBAN3172ggBfiFXP6lCg6UFPdU1hiq2PjkVwh1HXnMVbzped03mc5xcW8KaEZO0oud-OORE9nM_VArD7xsSyUhxv_v2YzuSddDmDyt6_99NqBEbwefH0E9_qe6YSpXcNt9kpomZqUmP7ov9CO%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FSNPVdeNIy_0Pw_eNLKEGoZc8Nv3jMH45zb13ZpFoOoyw-eVpBAN3172ggBfiFXP6lCg6UFPdU1hiq2PjkVwh1HXnMVbzped03mc5xcW8KaEZO0oud-OORE9nM_VArD7xsSyUhxv_v2YzuSddDmDyt6_99NqBEbwefH0E9_qe6YSpXcNt9kpomZqUmP7ov9CO%3Fpurpose%3Dfullsize" alt="Image" width="754" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FnOCUnFRp4I7o2cTTE9SW8vofr0vtR6pGiOmjVl_Fu8dyPdWlDkH1nyD5wRHhHs_rgfnydxvINmWHb6yB66k8yJtlBmFqJoS62nfWmVwd_E_ySpY02JOt2LEWkmnM17CTPQjqoLSfPFC59yKDEBvkKnQZrqCSKWEnrXnpcY9uQvoeuLknDIRuV2ZZtzJPpO68%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FnOCUnFRp4I7o2cTTE9SW8vofr0vtR6pGiOmjVl_Fu8dyPdWlDkH1nyD5wRHhHs_rgfnydxvINmWHb6yB66k8yJtlBmFqJoS62nfWmVwd_E_ySpY02JOt2LEWkmnM17CTPQjqoLSfPFC59yKDEBvkKnQZrqCSKWEnrXnpcY9uQvoeuLknDIRuV2ZZtzJPpO68%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FJLjAG_px0bfAly5UwDqRGNFpA-Fn9dbCQc4jl1U5KH4hF8SFw94eiwU9gba073sLKrXKTa_Z6zaEhNL-7hhCmQeLafyO2Rr0xdPOe5KOVfXTdvjr2dcGElOfPBVXlDp7KUeANxul0BnVE3LX1lZJJz3XjlBnfKbxUFh4b7e--yQlMKFhHj-pqUcGEUCNlrsf%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FJLjAG_px0bfAly5UwDqRGNFpA-Fn9dbCQc4jl1U5KH4hF8SFw94eiwU9gba073sLKrXKTa_Z6zaEhNL-7hhCmQeLafyO2Rr0xdPOe5KOVfXTdvjr2dcGElOfPBVXlDp7KUeANxul0BnVE3LX1lZJJz3XjlBnfKbxUFh4b7e--yQlMKFhHj-pqUcGEUCNlrsf%3Fpurpose%3Dfullsize" alt="Image" width="500" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F4ZtprkJxW2jmaexYOzJL_lrrktKVFHIoksFTJhqsPvPikInxP6oH04zF8aOTwFjJohLtPLaQGhvuFBbKKx2xi6ChRvWxbFaZSD4I950tRKYpRmqfaildWlG7zKyf3kckqP9lFPdK5B9Vbc_yzvXI_6gdODGXO5DUhhcL9JUgZitgfutauOjoahxJUS9-SrmQ%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F4ZtprkJxW2jmaexYOzJL_lrrktKVFHIoksFTJhqsPvPikInxP6oH04zF8aOTwFjJohLtPLaQGhvuFBbKKx2xi6ChRvWxbFaZSD4I950tRKYpRmqfaildWlG7zKyf3kckqP9lFPdK5B9Vbc_yzvXI_6gdODGXO5DUhhcL9JUgZitgfutauOjoahxJUS9-SrmQ%3Fpurpose%3Dfullsize" alt="Image" width="960" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FW8xJyDh2gpIcH7q8ZXzbKXFsRNuKO2GWKbo9cZ_m3JCmC5SI7B68Yxoy0n1UNl3QxWqHfuIKD0lUsWgTsina2mZft4k5nIPFFwuh0Yd0G5Ry2YBP4rvcE0-TEfpi89nou6wKLuuyAkdyuxLtS9WW89-L0u3rkXDpH9NZEGaSJGDINgRvHtgvePlR-i554UvX%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FW8xJyDh2gpIcH7q8ZXzbKXFsRNuKO2GWKbo9cZ_m3JCmC5SI7B68Yxoy0n1UNl3QxWqHfuIKD0lUsWgTsina2mZft4k5nIPFFwuh0Yd0G5Ry2YBP4rvcE0-TEfpi89nou6wKLuuyAkdyuxLtS9WW89-L0u3rkXDpH9NZEGaSJGDINgRvHtgvePlR-i554UvX%3Fpurpose%3Dfullsize" alt="Image" width="861" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FwuyqmD7UHwzp6H1H5f-8I8WFwi-JwXlQwVOl3bVXY4szTIGbQ-8Xf81se6I2F48Zd58n9QWJDeKC-CZfHy3QMxlCG0NWB2sqc_taI7BXLrQCn7E3kWBQPHbJoXMT6bHAjo44PtRcZMxx71_c0gvausGdC-hU-4QHsOJqNXt1MUn84l1SD9SF6rDZdLAUM9Px%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FwuyqmD7UHwzp6H1H5f-8I8WFwi-JwXlQwVOl3bVXY4szTIGbQ-8Xf81se6I2F48Zd58n9QWJDeKC-CZfHy3QMxlCG0NWB2sqc_taI7BXLrQCn7E3kWBQPHbJoXMT6bHAjo44PtRcZMxx71_c0gvausGdC-hU-4QHsOJqNXt1MUn84l1SD9SF6rDZdLAUM9Px%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Kruskal–Wallis H test&lt;/strong&gt; is commonly used to compare multiple independent groups when a one-way ANOVA is not appropriate.&lt;/p&gt;

&lt;p&gt;For example, imagine comparing customer spending across three cities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nairobi
Mombasa
Kisumu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Kruskal–Wallis test can be used to investigate whether the distributions differ across the groups.&lt;/p&gt;

&lt;p&gt;IBM describes the Kruskal–Wallis H test as a non-parametric analogue of one-way ANOVA for several independent samples. (&lt;a href="https://www.ibm.com/docs/en/spss-statistics/30.0.0?topic=samples-tests-several-independent-test-types&amp;amp;utm_source=chatgpt.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;If the test indicates a significant overall difference, additional post-hoc comparisons may be needed to determine which groups differ.&lt;/p&gt;




&lt;h1&gt;
  
  
  9. Pearson vs Spearman Correlation
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FKJNN2WdTdFeoKYRPkeF3l2bp2ruu-HpEanofH3wMbHGgrX22RfY5B3oFaNUUG04ZZWgynnC4hAmTzPxDOWS1b6hWbohPeru7MRzh71z9UVWHGWqKO2U0xRdYzfAuUR9EjOzWww_l_R7Is4RMlsfqIpgnX1GqX9cXkoQlJPTL52R-PEtvTztMLxr7nU3G7p0-%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FKJNN2WdTdFeoKYRPkeF3l2bp2ruu-HpEanofH3wMbHGgrX22RfY5B3oFaNUUG04ZZWgynnC4hAmTzPxDOWS1b6hWbohPeru7MRzh71z9UVWHGWqKO2U0xRdYzfAuUR9EjOzWww_l_R7Is4RMlsfqIpgnX1GqX9cXkoQlJPTL52R-PEtvTztMLxr7nU3G7p0-%3Fpurpose%3Dfullsize" alt="Image" width="1376" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FTsP1JBkoVdcGRQqOi9RpGc5AQzNnZfLDkSf1rw3alJAPr9P0ANS9ACJrKG4-vurqDp4FIbAccT-QAPi5p67L79bT2K7qNZ8ntz9CXVqB15Ls7T0ocNJEnIuxOmbeBA75vlhhWxawvE1ZJvaKiqcYvZxUjtxzD_p50U0M-_uVmT6Q7ssqZxHpXkp8kPN7IbUa%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FTsP1JBkoVdcGRQqOi9RpGc5AQzNnZfLDkSf1rw3alJAPr9P0ANS9ACJrKG4-vurqDp4FIbAccT-QAPi5p67L79bT2K7qNZ8ntz9CXVqB15Ls7T0ocNJEnIuxOmbeBA75vlhhWxawvE1ZJvaKiqcYvZxUjtxzD_p50U0M-_uVmT6Q7ssqZxHpXkp8kPN7IbUa%3Fpurpose%3Dfullsize" alt="Image" width="988" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FiGSRYDj73AFrukE1c_1U5y3m7deKDAN4cGiunnSe5-7oAHSsrrNIAuWOXcSIaOsHXHmhbzCFobQbd8ozn9bKuSnNAtF2uvESqPNOJkxzrsk_62Mz-1W6iAaViReL9yE1XtujjoNB-9d8lO0pSOlTD57O7dxiYnkYK8aGpVDcbWINfLmJsi2TzEFJiYVxdPQN%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FiGSRYDj73AFrukE1c_1U5y3m7deKDAN4cGiunnSe5-7oAHSsrrNIAuWOXcSIaOsHXHmhbzCFobQbd8ozn9bKuSnNAtF2uvESqPNOJkxzrsk_62Mz-1W6iAaViReL9yE1XtujjoNB-9d8lO0pSOlTD57O7dxiYnkYK8aGpVDcbWINfLmJsi2TzEFJiYVxdPQN%3Fpurpose%3Dfullsize" alt="Image" width="500" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FHoQ1SVkN6Ybp0GNUWbct0fyEKjuS-YEu1WIUWcZgqWkRGk2Ja6ndFlECFgPUP_9_YwcBkOrrSASqeQrmyz5mg14M_SgYJunMr6PsNMLRnP_KFzuYILTz1H6t--DhulsGal8u-vIRuRRbYaVHs7CIfxJ9hfeeT4LpOmNDFhghKG8ovfRhpSA4yOihRM2urCWC%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FHoQ1SVkN6Ybp0GNUWbct0fyEKjuS-YEu1WIUWcZgqWkRGk2Ja6ndFlECFgPUP_9_YwcBkOrrSASqeQrmyz5mg14M_SgYJunMr6PsNMLRnP_KFzuYILTz1H6t--DhulsGal8u-vIRuRRbYaVHs7CIfxJ9hfeeT4LpOmNDFhghKG8ovfRhpSA4yOihRM2urCWC%3Fpurpose%3Dfullsize" alt="Image" width="571" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Correlation measures the relationship between variables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pearson Correlation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pearson correlation&lt;/strong&gt; is commonly used to measure the strength and direction of a &lt;strong&gt;linear relationship&lt;/strong&gt; between numerical variables.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Is there a linear relationship between advertising expenditure and sales?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The correlation coefficient ranges from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-1  ←─── 0 ───→  +1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A value close to +1 indicates a strong positive linear relationship, while a value close to -1 indicates a strong negative linear relationship.&lt;/p&gt;

&lt;h3&gt;
  
  
  Spearman Rank Correlation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Spearman correlation&lt;/strong&gt; is based on ranks and can be useful when the relationship is monotonic but not necessarily linear, or when the assumptions behind Pearson correlation are not appropriate.&lt;/p&gt;

&lt;p&gt;It is particularly useful for &lt;strong&gt;ordinal data&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  10. Parametric vs Non-Parametric Tests
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FihjxWbab2hRQsBHlzPmznhClXRc4Ye79Bx6S6odaz9VVvhh6n7e3kkHR7SlmTxPfAqVKfV_A4W0_0GVYi2ga1c5tjptq8fIsQmyE1rWOOGaCVfySaSOTP9BiWBavuRmmLXJ-X_06ZOyAG53kAMDgLIIkFKZAKtdCbNXTSmf12DEFYtx-aFggi4g6k2BWYyRv%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FihjxWbab2hRQsBHlzPmznhClXRc4Ye79Bx6S6odaz9VVvhh6n7e3kkHR7SlmTxPfAqVKfV_A4W0_0GVYi2ga1c5tjptq8fIsQmyE1rWOOGaCVfySaSOTP9BiWBavuRmmLXJ-X_06ZOyAG53kAMDgLIIkFKZAKtdCbNXTSmf12DEFYtx-aFggi4g6k2BWYyRv%3Fpurpose%3Dfullsize" alt="Image" width="810" height="914"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fhly-IW-LVFDZyLjyrsJI3i1ds_Y803msTp7KdLZR_O6uEho6bcIDQWK3AylK_K2iGh-4O1USFGEfeUkmd3U9d4zrfj-9jNntNNdDOMeGiPQHN3vr9_YHInmk4eNePp1BMDG5IBRR59Dq36dTKRbI5WEbYpibCFfk5Tzb3r-O5aNXLUwuOvyfjrbW1Oepl6zB%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fhly-IW-LVFDZyLjyrsJI3i1ds_Y803msTp7KdLZR_O6uEho6bcIDQWK3AylK_K2iGh-4O1USFGEfeUkmd3U9d4zrfj-9jNntNNdDOMeGiPQHN3vr9_YHInmk4eNePp1BMDG5IBRR59Dq36dTKRbI5WEbYpibCFfk5Tzb3r-O5aNXLUwuOvyfjrbW1Oepl6zB%3Fpurpose%3Dfullsize" alt="Image" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FKiplJrOTAhwEkFhq38PkDlX5tQVgLfFyAFZh-H56aHfcOgEXWWsVnR8NM60JzXU-rEIoh8cRCAwuBQphLhWMCQEKJ5wJ68gFv2Ckfd7ulC7d-RFZLMY48Dvb1aAWTMX7Zri2iH_4mWF2FzA_O6JtpNG4W04oqmcnYH248SfxUgK_nRVQX8IshflgRW0_uzjg%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FKiplJrOTAhwEkFhq38PkDlX5tQVgLfFyAFZh-H56aHfcOgEXWWsVnR8NM60JzXU-rEIoh8cRCAwuBQphLhWMCQEKJ5wJ68gFv2Ckfd7ulC7d-RFZLMY48Dvb1aAWTMX7Zri2iH_4mWF2FzA_O6JtpNG4W04oqmcnYH248SfxUgK_nRVQX8IshflgRW0_uzjg%3Fpurpose%3Dfullsize" alt="Image" width="717" height="743"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FkCHJ3w9RzIITof3TIkmY8Adw3PInq6yCj8wr4aSWrz7uzs8uQKhLR_W56Ul2ulxY0O_boKnGoYQN1LK4Dy9ePmI_sAcWEHp8BNQaMGtcsDGMVcms-cpCKMTI6v9eqsl52zhgpxoxpIB4mvr8_Hi6-5Mnh6NdTkQ2eNX1AeqKuVoCGztD41W_TbBaTNHbfNdJ%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FkCHJ3w9RzIITof3TIkmY8Adw3PInq6yCj8wr4aSWrz7uzs8uQKhLR_W56Ul2ulxY0O_boKnGoYQN1LK4Dy9ePmI_sAcWEHp8BNQaMGtcsDGMVcms-cpCKMTI6v9eqsl52zhgpxoxpIB4mvr8_Hi6-5Mnh6NdTkQ2eNX1AeqKuVoCGztD41W_TbBaTNHbfNdJ%3Fpurpose%3Dfullsize" alt="Image" width="2048" height="1536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Situation&lt;/th&gt;
&lt;th&gt;Parametric Test&lt;/th&gt;
&lt;th&gt;Non-Parametric Alternative&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One sample vs a value&lt;/td&gt;
&lt;td&gt;One-sample t-test&lt;/td&gt;
&lt;td&gt;Wilcoxon signed-rank&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Two independent groups&lt;/td&gt;
&lt;td&gt;Independent t-test&lt;/td&gt;
&lt;td&gt;Mann–Whitney U&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Two paired groups&lt;/td&gt;
&lt;td&gt;Paired t-test&lt;/td&gt;
&lt;td&gt;Wilcoxon signed-rank&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Three or more independent groups&lt;/td&gt;
&lt;td&gt;One-way ANOVA&lt;/td&gt;
&lt;td&gt;Kruskal–Wallis&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linear correlation&lt;/td&gt;
&lt;td&gt;Pearson correlation&lt;/td&gt;
&lt;td&gt;Spearman correlation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This table should be treated as a &lt;strong&gt;general guide&lt;/strong&gt;, not an automatic substitution rule. The appropriate test depends on the measurement scale, study design, distribution, independence of observations, and the precise research question.&lt;/p&gt;




&lt;h1&gt;
  
  
  11. How to Choose the Right Test
&lt;/h1&gt;

&lt;p&gt;Before selecting a statistical test, a data scientist should ask several questions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: What type of data do I have?
&lt;/h3&gt;

&lt;p&gt;Determine whether your variables are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numerical&lt;/li&gt;
&lt;li&gt;Ordinal&lt;/li&gt;
&lt;li&gt;Nominal&lt;/li&gt;
&lt;li&gt;Binary&lt;/li&gt;
&lt;li&gt;Continuous or discrete&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2: How many groups am I comparing?
&lt;/h3&gt;

&lt;p&gt;Are you comparing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One group?&lt;/li&gt;
&lt;li&gt;Two groups?&lt;/li&gt;
&lt;li&gt;Three or more groups?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 3: Are the observations independent?
&lt;/h3&gt;

&lt;p&gt;Two groups may be independent, such as customers from two unrelated regions.&lt;/p&gt;

&lt;p&gt;Alternatively, the observations may be paired, such as measurements taken from the same individuals before and after treatment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: What does the distribution look like?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FiCu3_WFplxS5HvVFZExuAdXCoEXj7HM9e377E1DRYS9zmC3PDWOwqXFWQ3zTjcbKiFW2TCyQUf7x6oTUZpww-Lid3ZleKlHuIPZ4uO471nc4dU1LS448j2Og3WMrW89RgJZWscXh9D6NcFiezJfSawae_f-dYZesD4Nxpc5VZiUsWgKpA_6rD-9-xJiGtEMh%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FiCu3_WFplxS5HvVFZExuAdXCoEXj7HM9e377E1DRYS9zmC3PDWOwqXFWQ3zTjcbKiFW2TCyQUf7x6oTUZpww-Lid3ZleKlHuIPZ4uO471nc4dU1LS448j2Og3WMrW89RgJZWscXh9D6NcFiezJfSawae_f-dYZesD4Nxpc5VZiUsWgKpA_6rD-9-xJiGtEMh%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fsuz926py8fPOcepc9I0tLP6-1I3vwvd868QzIyFfWnp7kJp4g_yjkyOZqZUzIW-z02oyw06wAq2OWRLukuyl4VTVr26WmAWq-RIEPKRLKXmwnlUXnp-6-DBQQqeknWA9VU2CdNWFI_wtY7Hi2WN5Y1f-v21cBDHrpCVEpoJEhzU5FJ-KYqlqKWqg3OmXV0C0%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fsuz926py8fPOcepc9I0tLP6-1I3vwvd868QzIyFfWnp7kJp4g_yjkyOZqZUzIW-z02oyw06wAq2OWRLukuyl4VTVr26WmAWq-RIEPKRLKXmwnlUXnp-6-DBQQqeknWA9VU2CdNWFI_wtY7Hi2WN5Y1f-v21cBDHrpCVEpoJEhzU5FJ-KYqlqKWqg3OmXV0C0%3Fpurpose%3Dfullsize" alt="Image" width="900" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FLjGZUsMT-pldDdKW7BNzzZhGeh--DU3VDMghHIpPJOPCQJtZiFyf2IZgn81Mj4Za7n3R2jbxYAoGtn7ZY-40OPVYkFDwWGo1gsInGcK-wA3gcZbOQkaJwAoF2HMCgWtygiPZhtJs9WP3QowYxv19cJxuPd8a0wInN8B5W0qrM8HV3B7SlKMj2w-r0M36-JSX%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FLjGZUsMT-pldDdKW7BNzzZhGeh--DU3VDMghHIpPJOPCQJtZiFyf2IZgn81Mj4Za7n3R2jbxYAoGtn7ZY-40OPVYkFDwWGo1gsInGcK-wA3gcZbOQkaJwAoF2HMCgWtygiPZhtJs9WP3QowYxv19cJxuPd8a0wInN8B5W0qrM8HV3B7SlKMj2w-r0M36-JSX%3Fpurpose%3Dfullsize" alt="Image" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F5fo5wcMWO99re9sxra0dyb2xOJwBV31Si1PWeWXaSJRNBt8vxqR0p0z12QP14CUIRJjBp3mUn6cpYJzJuYS2bhaxE3T_bBcgFrGru8Jfb5z7MZIcT2QTq98Cfcw4P8qo6GE0lkT5meC-tUAqNqvKPh0TQHsxvuvGIbCECDZ7uJHpWwPkTykFyC1j6JEOlf_7%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2F5fo5wcMWO99re9sxra0dyb2xOJwBV31Si1PWeWXaSJRNBt8vxqR0p0z12QP14CUIRJjBp3mUn6cpYJzJuYS2bhaxE3T_bBcgFrGru8Jfb5z7MZIcT2QTq98Cfcw4P8qo6GE0lkT5meC-tUAqNqvKPh0TQHsxvuvGIbCECDZ7uJHpWwPkTykFyC1j6JEOlf_7%3Fpurpose%3Dfullsize" alt="Image" width="1583" height="1171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fi1CVeecu5H3zq2xOG4Y31YO1NaHNuZXjTMbVoHvO3Kxnkp2uv5ac2lbi3Y8EjUdZH8T_ghMD_lMWhz7hKGEDaAuxhQYV9P27t5fU8PgnkaByryYvyW17cZIFbVyn5qNHZ_SP2YNF3AE7tk1uRbOn_hPaIup4bnOZuDlpwC_Rr2ptuRE5PvgOKkalq_FEpgQV%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fi1CVeecu5H3zq2xOG4Y31YO1NaHNuZXjTMbVoHvO3Kxnkp2uv5ac2lbi3Y8EjUdZH8T_ghMD_lMWhz7hKGEDaAuxhQYV9P27t5fU8PgnkaByryYvyW17cZIFbVyn5qNHZ_SP2YNF3AE7tk1uRbOn_hPaIup4bnOZuDlpwC_Rr2ptuRE5PvgOKkalq_FEpgQV%3Fpurpose%3Dfullsize" alt="Image" width="2133" height="1183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FBFHd9hN6ivSJsIj1okqSDYfNapQYF86OX14-qIgWNpVcIiDTNLqEmb_WbbL8--UX0cUDjQ8pzpuuiygYrHrCKZVCYcln670_QmdyJ_ZJ2-kFU1sXKJbXfYblUiukL1KIUUVLsc-HBCREslCNOJWFfdjGdegQCk8nJQkc4buMpXnDhkLhKGMgpKjabE6W7t1B%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FBFHd9hN6ivSJsIj1okqSDYfNapQYF86OX14-qIgWNpVcIiDTNLqEmb_WbbL8--UX0cUDjQ8pzpuuiygYrHrCKZVCYcln670_QmdyJ_ZJ2-kFU1sXKJbXfYblUiukL1KIUUVLsc-HBCREslCNOJWFfdjGdegQCk8nJQkc4buMpXnDhkLhKGMgpKjabE6W7t1B%3Fpurpose%3Dfullsize" alt="Image" width="1312" height="952"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Exploratory data analysis can help you understand distributions, identify outliers, and determine whether the assumptions of a statistical method are reasonable. IBM describes EDA as a process for investigating datasets, summarizing their characteristics, discovering patterns, identifying anomalies, and checking assumptions before more formal analysis. (&lt;a href="https://www.ibm.com/think/topics/exploratory-data-analysis?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Useful tools include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Histograms&lt;/li&gt;
&lt;li&gt;Box plots&lt;/li&gt;
&lt;li&gt;Q-Q plots&lt;/li&gt;
&lt;li&gt;Descriptive statistics&lt;/li&gt;
&lt;li&gt;Normality assessments&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 5: Check assumptions
&lt;/h3&gt;

&lt;p&gt;Don't automatically use a parametric test simply because your variable is numerical.&lt;/p&gt;

&lt;p&gt;Check assumptions relevant to the specific test, which may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Independence&lt;/li&gt;
&lt;li&gt;Distributional assumptions&lt;/li&gt;
&lt;li&gt;Equal or comparable variances&lt;/li&gt;
&lt;li&gt;Appropriate measurement level&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  12. Statistical Testing in Python
&lt;/h1&gt;

&lt;p&gt;Python provides several libraries for statistical analysis, including &lt;strong&gt;SciPy&lt;/strong&gt;, which contains many statistical tests.&lt;/p&gt;

&lt;p&gt;For example, an independent t-test can be performed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy.stats&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ttest_ind&lt;/span&gt;

&lt;span class="n"&gt;statistic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ttest_ind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group_b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Statistic:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;statistic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;P-value:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p_value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Mann–Whitney U test can be performed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy.stats&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mannwhitneyu&lt;/span&gt;

&lt;span class="n"&gt;statistic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mannwhitneyu&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group_b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Statistic:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;statistic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;P-value:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p_value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important lesson is that &lt;strong&gt;running the code is only one part of statistical analysis&lt;/strong&gt;. A data scientist must also understand why a particular test was selected and how its assumptions affect interpretation.&lt;/p&gt;




&lt;h1&gt;
  
  
  13. Understanding the P-Value
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;p-value&lt;/strong&gt; is one of the most commonly misunderstood concepts in statistics.&lt;/p&gt;

&lt;p&gt;In hypothesis testing, the p-value represents the probability, under the null hypothesis and the test's assumptions, of obtaining a result at least as extreme as the observed result.&lt;/p&gt;

&lt;p&gt;A common significance level is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;α = 0.05
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p-value &amp;lt; 0.05
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;researchers often describe the result as &lt;strong&gt;statistically significant&lt;/strong&gt; at the 5% level and reject the null hypothesis.&lt;/p&gt;

&lt;p&gt;If:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p-value ≥ 0.05
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we generally &lt;strong&gt;fail to reject&lt;/strong&gt; the null hypothesis.&lt;/p&gt;

&lt;p&gt;Importantly, failing to reject the null hypothesis does &lt;strong&gt;not&lt;/strong&gt; prove that the null hypothesis is true.&lt;/p&gt;

&lt;p&gt;Statistical significance also does not automatically mean that an effect is practically important. A data scientist should consider the &lt;strong&gt;effect size, confidence interval, sample size, and real-world context&lt;/strong&gt; alongside the p-value.&lt;/p&gt;




&lt;h1&gt;
  
  
  14. Why These Tests Matter in Data Science
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FHx2xQkMI4iO_3c-8MZET7zqKv-M5Tj-UmGLVEDt8eoBe5bI0j0db7H5cDYDyC4opT1WaNFD4iN626EW_3WgHa2v5sOtDC4SAhXMJpfGvZVaOL5WBnX402TkU4DehnCBCZ9CPjbqQRcpkC5Nquqt4qJbn_tvX7asGGRK1BofWyg-p5vPWqUkPbHigbGL4patW%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FHx2xQkMI4iO_3c-8MZET7zqKv-M5Tj-UmGLVEDt8eoBe5bI0j0db7H5cDYDyC4opT1WaNFD4iN626EW_3WgHa2v5sOtDC4SAhXMJpfGvZVaOL5WBnX402TkU4DehnCBCZ9CPjbqQRcpkC5Nquqt4qJbn_tvX7asGGRK1BofWyg-p5vPWqUkPbHigbGL4patW%3Fpurpose%3Dfullsize" alt="Image" width="1792" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FpjNCZNXGws-R-chNV5-6VlmI8aOW7l9OZd04t0-pEWqXNNV7XsQBTIHYoVrgDKgO9JEaYON8h1injJzKAvq88Pjg_fMUNtX8HNe7RE3rVQrxgDCJYacjsvs-f2D3jfLPQWOshx-_EBWJQUxl-Q1k6UXpS3BaBQrs5JZ_7iZur6foUejw2PXs_8xSHx9aRSCq%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FpjNCZNXGws-R-chNV5-6VlmI8aOW7l9OZd04t0-pEWqXNNV7XsQBTIHYoVrgDKgO9JEaYON8h1injJzKAvq88Pjg_fMUNtX8HNe7RE3rVQrxgDCJYacjsvs-f2D3jfLPQWOshx-_EBWJQUxl-Q1k6UXpS3BaBQrs5JZ_7iZur6foUejw2PXs_8xSHx9aRSCq%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FT-p7wlab1D9t7l9yOrOT6lIuJvfN5MI3GQMQoR0I-aK39H3L_OElVBK0e0v4KjPNlF5lGhNTiM-m9bZEZyZG-RhlM1K6Ga4I7SLtnvUlqOsgcOSVZDzE18-0F3qAuXo45Tv5eWZRqDnG76Po0rDN_BswtNPf2azPaGlyM8PTQ8VVcCQyow70qlgl2LMRQKWd%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FT-p7wlab1D9t7l9yOrOT6lIuJvfN5MI3GQMQoR0I-aK39H3L_OElVBK0e0v4KjPNlF5lGhNTiM-m9bZEZyZG-RhlM1K6Ga4I7SLtnvUlqOsgcOSVZDzE18-0F3qAuXo45Tv5eWZRqDnG76Po0rDN_BswtNPf2azPaGlyM8PTQ8VVcCQyow70qlgl2LMRQKWd%3Fpurpose%3Dfullsize" alt="Image" width="1080" height="1080"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FoHz3jQ7b5CGDRbniC9u8PumESX8HHgG3HRq91qtVxYkahbGFo1lCmWbd7ElnjQpMUcYs-XV3uLZO_Jw2ofuJ3uxOH8nS6T8of7a8nbA92cDhlWpRLf_y13CyaKSdCEz_10TY_UgNMM-NAEVes5sRcryqLC-Te9NRJrHfOZgyQAnWB_O9OoWn39OxiRJZXnVv%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2FoHz3jQ7b5CGDRbniC9u8PumESX8HHgG3HRq91qtVxYkahbGFo1lCmWbd7ElnjQpMUcYs-XV3uLZO_Jw2ofuJ3uxOH8nS6T8of7a8nbA92cDhlWpRLf_y13CyaKSdCEz_10TY_UgNMM-NAEVes5sRcryqLC-Te9NRJrHfOZgyQAnWB_O9OoWn39OxiRJZXnVv%3Fpurpose%3Dfullsize" alt="Image" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fl00dcIbj06ccO4QSDvttbAlHPyzWTfG4_NvYbErcu9CMlLI5_SttELCpM8syAj6n3_EcLc0ypV4gwwgSx_d7eZDL5aSRw2OVhO9_pDpJ4fbNWZ4r7t_fkj5IqeB_UnDn4ky0LXcXSIOSRmEGEvZOsCMbOYa9tAUL8B-Ss3VE01X6__ytONYj1O9ZF7GVZtIO%3Fpurpose%3Dfullsize" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.openai.com%2Fstatic-rsc-4%2Fl00dcIbj06ccO4QSDvttbAlHPyzWTfG4_NvYbErcu9CMlLI5_SttELCpM8syAj6n3_EcLc0ypV4gwwgSx_d7eZDL5aSRw2OVhO9_pDpJ4fbNWZ4r7t_fkj5IqeB_UnDn4ky0LXcXSIOSRmEGEvZOsCMbOYa9tAUL8B-Ss3VE01X6__ytONYj1O9ZF7GVZtIO%3Fpurpose%3Dfullsize" alt="Image" width="1200" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Statistics plays an important role throughout the data science workflow.&lt;/p&gt;

&lt;p&gt;A typical process might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Raw Data
   ↓
Data Cleaning
   ↓
Exploratory Data Analysis
   ↓
Statistical Testing
   ↓
Feature Analysis
   ↓
Machine Learning
   ↓
Model Evaluation
   ↓
Business Decision
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Statistical testing can help data scientists determine whether patterns observed during analysis are likely to represent meaningful relationships rather than random variation.&lt;/p&gt;

&lt;p&gt;For example, before building a machine-learning model, you might investigate whether certain variables differ between groups or whether particular variables are associated with an outcome.&lt;/p&gt;

&lt;p&gt;However, statistical significance should not be confused with predictive usefulness. A variable can have a statistically significant relationship with an outcome while contributing little practical value to a predictive model.&lt;/p&gt;




&lt;h1&gt;
  
  
  15. A Practical Example
&lt;/h1&gt;

&lt;p&gt;Imagine that a company wants to determine whether a new training program improved employee productivity.&lt;/p&gt;

&lt;p&gt;The company measures productivity &lt;strong&gt;before and after training&lt;/strong&gt; for the same employees.&lt;/p&gt;

&lt;p&gt;Because the measurements are paired, the analyst might consider:&lt;/p&gt;

&lt;h3&gt;
  
  
  Parametric approach
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Paired t-test&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;if the assumptions for that test are reasonably satisfied.&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-parametric approach
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Wilcoxon signed-rank test&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;if a non-parametric approach is more appropriate.&lt;/p&gt;

&lt;p&gt;The hypotheses could be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H₀: The training did not change productivity.

H₁: The training changed productivity.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After performing the test, the analyst examines the p-value along with the size and direction of the observed change.&lt;/p&gt;

&lt;p&gt;The final conclusion should consider both statistical evidence and the practical importance of the result.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Parametric and non-parametric tests are important tools in statistical analysis and data science.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parametric tests&lt;/strong&gt; can be powerful when their assumptions are reasonably satisfied. Common examples include the &lt;strong&gt;t-tests, ANOVA, and Pearson correlation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-parametric tests&lt;/strong&gt; provide alternatives when stronger distributional assumptions are inappropriate or when the data are ordinal, highly skewed, or otherwise unsuitable for a particular parametric procedure. Examples include the &lt;strong&gt;Mann–Whitney U test, Wilcoxon signed-rank test, Kruskal–Wallis test, and Spearman correlation&lt;/strong&gt;. (&lt;a href="https://www.ibm.com/docs/en/spss-statistics/32.0.0?topic=features-nonparametric-tests&amp;amp;utm_source=chatgpt.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The goal is not to memorize a list of tests. A good data scientist should understand the &lt;strong&gt;research question, type of data, study design, assumptions, and interpretation&lt;/strong&gt; before selecting a statistical method.&lt;/p&gt;

&lt;p&gt;Ultimately, statistical testing helps transform raw observations into evidence that can support better scientific, business, and data-driven decisions.&lt;/p&gt;

</description>
    </item>
    <item>
      <title># Introduction to SQL: DDL, DML, and Data Querying</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Mon, 17 Aug 2026 09:48:56 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/-introduction-to-sql-ddl-dml-and-data-querying-6fp</link>
      <guid>https://dev.to/samuel_mwai/-introduction-to-sql-ddl-dml-and-data-querying-6fp</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2wtsnk16f7tlssqltbj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2wtsnk16f7tlssqltbj7.png" alt=" " width="800" height="801"&gt;&lt;/a&gt;&lt;br&gt;
In today's data-driven world, databases are used to store enormous amounts of information. Businesses use them to manage customers, transactions, employees, products, financial records, and many other types of data. To interact with these databases, one of the most important languages to learn is &lt;strong&gt;SQL&lt;/strong&gt;, or &lt;strong&gt;Structured Query Language&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;SQL allows users to create database structures, insert and modify information, and retrieve specific data for analysis. PostgreSQL, MySQL, SQL Server, and Oracle are examples of database systems that support SQL.&lt;/p&gt;

&lt;p&gt;For anyone learning &lt;strong&gt;data science, data analytics, or database management&lt;/strong&gt;, understanding the basic SQL commands is essential. Three important areas to understand are &lt;strong&gt;Data Definition Language (DDL), Data Manipulation Language (DML), and data querying&lt;/strong&gt;.&lt;/p&gt;


&lt;h1&gt;
  
  
  1. Understanding DDL
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL DDL CREATE ALTER DROP TRUNCATE infographic]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DDL stands for Data Definition Language.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DDL is concerned with the &lt;strong&gt;structure of the database&lt;/strong&gt; rather than the individual records stored inside it. It is used to create database objects and modify their structure.&lt;/p&gt;

&lt;p&gt;Common DDL commands include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CREATE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ALTER&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DROP&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TRUNCATE&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  CREATE
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;CREATE&lt;/code&gt; command can be used to create a table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a &lt;code&gt;customers&lt;/code&gt; table containing four columns.&lt;/p&gt;

&lt;h3&gt;
  
  
  ALTER
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;ALTER&lt;/code&gt; command modifies an existing table.&lt;/p&gt;

&lt;p&gt;For example, we can add an email column:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DROP
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;DROP&lt;/code&gt; removes a database object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This removes the entire &lt;code&gt;customers&lt;/code&gt; table, including its structure and data.&lt;/p&gt;

&lt;h3&gt;
  
  
  TRUNCATE
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;TRUNCATE&lt;/code&gt; removes the rows from a table while keeping the table itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;TRUNCATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore, DDL can be thought of as the part of SQL responsible for &lt;strong&gt;building and changing the database structure&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. Understanding DML
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL DML INSERT UPDATE DELETE infographic]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DML stands for Data Manipulation Language.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While DDL deals primarily with the structure of the database, DML deals with the &lt;strong&gt;data stored inside tables&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The most common DML commands are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;INSERT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UPDATE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DELETE&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  INSERT
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;INSERT&lt;/code&gt; is used to add new records.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Samuel'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Nairobi'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This adds a new customer to the table.&lt;/p&gt;

&lt;p&gt;Multiple records can also be inserted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Mombasa'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Mary'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Kisumu'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Peter'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Nakuru'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  UPDATE
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;UPDATE&lt;/code&gt; changes existing records.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Nairobi'&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;WHERE&lt;/code&gt; condition is extremely important because it specifies which record should be changed.&lt;/p&gt;

&lt;h3&gt;
  
  
  DELETE
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;DELETE&lt;/code&gt; removes records.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, the &lt;code&gt;WHERE&lt;/code&gt; clause prevents you from accidentally deleting every record in the table.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Data Querying with SELECT
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL SELECT query and database results illustration]&lt;/p&gt;

&lt;p&gt;One of the most important things you will do with SQL is &lt;strong&gt;query data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A query is a request for information from a database. The &lt;code&gt;SELECT&lt;/code&gt; statement is used to retrieve data from a table.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;*&lt;/code&gt; means that we want all columns.&lt;/p&gt;

&lt;p&gt;You can also select only the columns you need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the result more focused and easier to analyze.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. Filtering Data with WHERE
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL WHERE clause filtering rows diagram]&lt;/p&gt;

&lt;p&gt;When working with large datasets, you often don't want every record. You may only want records that meet a particular condition.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;WHERE&lt;/code&gt; clause allows you to filter your results.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Nairobi'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns only customers whose city is Nairobi.&lt;/p&gt;

&lt;p&gt;You can also use comparison operators:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SQL supports operators such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;=&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also combine conditions using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;AND&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;OR&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NOT&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Nairobi'&lt;/span&gt;
&lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  5. Sorting Data with ORDER BY
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL ORDER BY sorting data illustration]&lt;/p&gt;

&lt;p&gt;Sometimes you want your results arranged in a particular order.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ORDER BY&lt;/code&gt; clause allows you to sort the results.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="k"&gt;ASC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sorts customers from the youngest to the oldest.&lt;/p&gt;

&lt;p&gt;To sort from highest to lowest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ORDER BY&lt;/code&gt; is especially useful when analyzing rankings, sales, salaries, scores, or other numerical data.&lt;/p&gt;




&lt;h1&gt;
  
  
  6. GROUP BY and Aggregate Functions
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL GROUP BY COUNT SUM AVG visualization]&lt;/p&gt;

&lt;p&gt;SQL is not only useful for retrieving individual records. It can also be used to &lt;strong&gt;summarize data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Common aggregate functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;COUNT()&lt;/code&gt; — counts records&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SUM()&lt;/code&gt; — calculates a total&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AVG()&lt;/code&gt; — calculates an average&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MIN()&lt;/code&gt; — finds the smallest value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MAX()&lt;/code&gt; — finds the largest value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns the total number of customers.&lt;/p&gt;

&lt;p&gt;We can also calculate the average age:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  GROUP BY
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;GROUP BY&lt;/code&gt; allows us to organize records into groups.&lt;/p&gt;

&lt;p&gt;For example, we can count customers by city:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result could look like:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;City&lt;/th&gt;
&lt;th&gt;Customer Count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Nairobi&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mombasa&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kisumu&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nakuru&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This type of query is particularly useful in &lt;strong&gt;data analytics&lt;/strong&gt;, because it allows large datasets to be summarized into meaningful information.&lt;/p&gt;




&lt;h1&gt;
  
  
  7. Putting SQL Together
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL query flow SELECT FROM WHERE ORDER BY LIMIT]&lt;/p&gt;

&lt;p&gt;The real power of SQL comes from combining these commands.&lt;/p&gt;

&lt;p&gt;Suppose we want to find the three oldest customers from Nairobi.&lt;/p&gt;

&lt;p&gt;We could write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Nairobi'&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, several SQL concepts work together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT   → Choose the columns
FROM     → Choose the table
WHERE    → Filter the records
ORDER BY → Sort the results
LIMIT    → Restrict the number of results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the foundation of more advanced SQL queries, including joins, subqueries, common table expressions, and window functions.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. DDL vs DML vs Data Querying
&lt;/h1&gt;

&lt;p&gt;[IMAGE: SQL DDL DML DQL comparison infographic]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;th&gt;Common Commands&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;DDL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Defines database structure&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;CREATE&lt;/code&gt;, &lt;code&gt;ALTER&lt;/code&gt;, &lt;code&gt;DROP&lt;/code&gt;, &lt;code&gt;TRUNCATE&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;DML&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Manipulates stored data&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Querying&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Retrieves information&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;GROUP BY&lt;/code&gt;, &lt;code&gt;ORDER BY&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The easiest way to remember the difference is:&lt;/p&gt;

&lt;h3&gt;
  
  
  DDL → Structure
&lt;/h3&gt;

&lt;p&gt;Build and modify the database structure.&lt;/p&gt;

&lt;h3&gt;
  
  
  DML → Data
&lt;/h3&gt;

&lt;p&gt;Add, change, and remove records.&lt;/p&gt;

&lt;h3&gt;
  
  
  Querying → Information
&lt;/h3&gt;

&lt;p&gt;Retrieve and analyze information stored in the database.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;SQL is one of the fundamental skills for anyone working with databases and data. DDL provides the commands needed to create and modify database structures, while DML allows users to insert, update, and delete information. Data querying, particularly through &lt;code&gt;SELECT&lt;/code&gt;, allows users to retrieve and analyze the information stored in those structures.&lt;/p&gt;

&lt;p&gt;Once these fundamentals are understood, you can progress to more powerful SQL concepts such as &lt;strong&gt;JOINs, subqueries, CTEs, window functions, views, indexes, and advanced aggregation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For a data analyst or data scientist, SQL is more than simply a database language—it is a practical tool for turning large amounts of raw data into information that can be analyzed and used for decision-making.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;SQL provides a structured way to work with databases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DDL&lt;/strong&gt; manages database structure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DML&lt;/strong&gt; manages the data stored in tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SELECT&lt;/strong&gt; retrieves information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WHERE&lt;/strong&gt; filters data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ORDER BY&lt;/strong&gt; sorts data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GROUP BY&lt;/strong&gt; organizes data into groups.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aggregate functions&lt;/strong&gt; summarize data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, these concepts form the foundation for working with relational databases and provide an important starting point for anyone pursuing a career in &lt;strong&gt;data analytics, data science, or database management&lt;/strong&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Subqueries and CTEs in SQL: A Complete Guide</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Mon, 17 Aug 2026 09:37:27 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/understanding-subqueries-and-ctes-in-sql-a-complete-guide-49i8</link>
      <guid>https://dev.to/samuel_mwai/understanding-subqueries-and-ctes-in-sql-a-complete-guide-49i8</guid>
      <description>&lt;p&gt;Understanding Subqueries and CTEs in SQL: A Complete Guide&lt;/p&gt;

&lt;p&gt;beginners&lt;/p&gt;

&lt;p&gt;tutorial&lt;/p&gt;

&lt;p&gt;productivity&lt;br&gt;
Working with relational databases often requires breaking down complex problems into manageable parts. Two powerful tools that help achieve this in SQL are subqueries and Common Table Expressions (CTEs). While they may seem similar at first, they serve different purposes and are best used in different scenarios.&lt;/p&gt;

&lt;p&gt;This article explores what subqueries and CTEs are, their types, use cases, and how they compare in terms of performance and readability.&lt;/p&gt;

&lt;p&gt;What is a Subquery?&lt;/p&gt;

&lt;p&gt;A subquery is a query nested inside another SQL query. It is used to perform operations that depend on the result of another query.&lt;/p&gt;

&lt;p&gt;Basic Example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;&lt;strong&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="SELECT" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;SELECT&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/strong&gt;&lt;/div&gt;&lt;strong&gt;
**&lt;br&gt;
The inner query calculates the average salary.&lt;br&gt;
The outer query retrieves employees earning above that average.&lt;/strong&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;👉 In simple terms, a subquery provides intermediate results to the main query.&lt;/p&gt;

&lt;p&gt;Types of Subqueries&lt;/p&gt;

&lt;p&gt;Subqueries can be categorized based on how they are used and how they interact with the outer query.&lt;/p&gt;

&lt;p&gt;Single-row Subquery&lt;br&gt;
Returns only one row.&lt;/p&gt;

&lt;p&gt;SELECT name&lt;br&gt;
FROM employees&lt;br&gt;
WHERE department_id = (&lt;br&gt;
    SELECT id FROM departments WHERE name = 'Sales'&lt;br&gt;
);&lt;br&gt;
Multi-row Subquery&lt;br&gt;
Returns multiple rows and is used with operators like IN, ANY, or ALL.&lt;/p&gt;

&lt;p&gt;SELECT name&lt;br&gt;
FROM employees&lt;br&gt;
WHERE department_id IN (&lt;br&gt;
    SELECT id FROM departments WHERE location = 'Nairobi'&lt;br&gt;
);&lt;br&gt;
Correlated Subquery&lt;br&gt;
Depends on the outer query and is executed once for each row.&lt;/p&gt;

&lt;p&gt;SELECT name&lt;br&gt;
FROM employees e&lt;br&gt;
WHERE salary &amp;gt; (&lt;br&gt;
    SELECT AVG(salary)&lt;br&gt;
    FROM employees&lt;br&gt;
    WHERE department_id = e.department_id&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;👉 This is more dynamic but can be slower due to repeated execution.&lt;/p&gt;

&lt;p&gt;Nested Subquery&lt;br&gt;
A subquery inside another subquery.&lt;/p&gt;

&lt;p&gt;SELECT name&lt;br&gt;
FROM employees&lt;br&gt;
WHERE department_id = (&lt;br&gt;
    SELECT id&lt;br&gt;
    FROM departments&lt;br&gt;
    WHERE location = (&lt;br&gt;
        SELECT location&lt;br&gt;
        FROM offices&lt;br&gt;
        WHERE city = 'Nairobi'&lt;br&gt;
    )&lt;br&gt;
);&lt;br&gt;
When Should Subqueries Be Used?&lt;/p&gt;

&lt;p&gt;Subqueries are ideal when:&lt;/p&gt;

&lt;p&gt;You need a value derived from another query&lt;br&gt;
The logic is simple and contained&lt;br&gt;
You want to filter results dynamically&lt;br&gt;
You’re working with aggregates (AVG, MAX, MIN, etc.)&lt;/p&gt;

&lt;p&gt;However, they can become inefficient or hard to read when deeply nested or correlated.&lt;/p&gt;

&lt;p&gt;What are CTEs (Common Table Expressions)?&lt;/p&gt;

&lt;p&gt;A Common Table Expression (CTE) is a temporary result set defined at the beginning of a query using the WITH keyword. It improves readability and organization, especially in complex queries.&lt;/p&gt;

&lt;p&gt;Basic Example&lt;br&gt;
WITH avg_salary AS (&lt;br&gt;
    SELECT AVG(salary) AS avg_sal&lt;br&gt;
    FROM employees&lt;br&gt;
)&lt;br&gt;
SELECT name&lt;br&gt;
FROM employees, avg_salary&lt;br&gt;
WHERE salary &amp;gt; avg_sal;&lt;br&gt;
👉 Think of a CTE as a temporary named query you can reference within your main query.&lt;/p&gt;

&lt;p&gt;Types and Use Cases of CTEs&lt;/p&gt;

&lt;p&gt;Non-Recursive CTE&lt;br&gt;
The most common type, used for simplifying complex queries.&lt;/p&gt;

&lt;p&gt;WITH department_totals AS (&lt;br&gt;
    SELECT department_id, SUM(salary) AS total_salary&lt;br&gt;
    FROM employees&lt;br&gt;
    GROUP BY department_id&lt;br&gt;
)&lt;br&gt;
SELECT *&lt;br&gt;
FROM department_totals&lt;br&gt;
WHERE total_salary &amp;gt; 50000;&lt;/p&gt;

&lt;p&gt;Use case:&lt;/p&gt;

&lt;p&gt;Breaking down large queries into readable parts&lt;/p&gt;

&lt;p&gt;Recursive CTE&lt;br&gt;
Used to handle hierarchical or tree-structured data.&lt;/p&gt;

&lt;p&gt;WITH RECURSIVE employee_hierarchy AS (&lt;br&gt;
    SELECT id, name, manager_id&lt;br&gt;
    FROM employees&lt;br&gt;
    WHERE manager_id IS NULL&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UNION ALL

SELECT e.id, e.name, e.manager_id
FROM employees e
INNER JOIN employee_hierarchy eh
ON e.manager_id = eh.id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;)&lt;br&gt;
SELECT * FROM employee_hierarchy;&lt;/p&gt;

&lt;p&gt;Use case:&lt;/p&gt;

&lt;p&gt;Organizational charts&lt;br&gt;
Category hierarchies&lt;br&gt;
Graph traversal&lt;br&gt;
When Should CTEs Be Used?&lt;/p&gt;

&lt;p&gt;CTEs are best when:&lt;/p&gt;

&lt;p&gt;Queries are complex and need structure&lt;br&gt;
You want to reuse a result multiple times&lt;br&gt;
You need recursive logic&lt;br&gt;
You want to improve readability and maintainability&lt;br&gt;
Subqueries vs CTEs: A Clear Comparison&lt;/p&gt;

&lt;p&gt;Readability Subqueries: Can become difficult to read when nested CTEs: Much cleaner and easier to understand&lt;br&gt;
👉 Winner: CTEs&lt;/p&gt;

&lt;p&gt;Performance Subqueries: Correlated subqueries can be slow Often re-executed multiple times CTEs: Sometimes optimized better by the database But in some systems, they may not be cached and can behave like inline views&lt;br&gt;
👉 Winner: Depends on the database engine&lt;/p&gt;

&lt;p&gt;For repeated logic → CTEs often better&lt;br&gt;
For simple tasks → subqueries are fine&lt;/p&gt;

&lt;p&gt;Reusability Subqueries: Cannot be reused easily CTEs: Can be referenced multiple times in the same query&lt;br&gt;
👉 Winner: CTEs&lt;/p&gt;

&lt;p&gt;Complexity Handling Subqueries: Good for simple conditions CTEs: Ideal for complex, multi-step logic&lt;br&gt;
👉 Winner: CTEs&lt;/p&gt;

&lt;p&gt;Recursion Subqueries: Cannot handle recursion CTEs: Support recursive queries&lt;br&gt;
👉 Winner: CTEs&lt;/p&gt;

&lt;p&gt;When to Use Each&lt;br&gt;
Use Subqueries when:&lt;br&gt;
The query is simple and short&lt;br&gt;
You only need the result once&lt;br&gt;
You’re filtering using aggregates&lt;br&gt;
Use CTEs when:&lt;br&gt;
The query is complex or layered&lt;br&gt;
You need better readability&lt;br&gt;
You want to reuse logic&lt;br&gt;
You’re working with hierarchical data&lt;br&gt;
Conclusion&lt;/p&gt;

&lt;p&gt;Both subqueries and CTEs are essential tools in SQL, and understanding when to use each can significantly improve your queries.&lt;/p&gt;

&lt;p&gt;Subqueries are concise and useful for straightforward operations&lt;br&gt;
CTEs provide structure, clarity, and power for more advanced scenarios&lt;/p&gt;

&lt;p&gt;In practice, experienced developers often prefer CTEs for maintainability, especially in large projects—but subqueries still have their place for quick, simple tasks.&lt;/p&gt;

&lt;p&gt;Top comments (0)&lt;/p&gt;

&lt;p&gt;Subscribe&lt;br&gt;
pic&lt;br&gt;
Add to the discussion&lt;/p&gt;

&lt;p&gt;Code of Conduct • Report abuse&lt;br&gt;
profile&lt;br&gt;
The DEV Team&lt;br&gt;
Promoted&lt;/p&gt;

&lt;p&gt;Google article image&lt;/p&gt;

&lt;p&gt;Architect A Personalized Multi-Agent System with Long-Term Memory&lt;br&gt;
In support of our mission to accelerate the developer journey on Google Cloud, we built Dev Signal — a multi-agent system designed to transform raw community signals into reliable technical guidance by automating the path from discovery to expert creation.&lt;/p&gt;

&lt;p&gt;Read more →&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Distributions and Their Impact on Data Science</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Mon, 22 Jun 2026 06:51:33 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/distributions-and-their-impact-on-data-science-50k4</link>
      <guid>https://dev.to/samuel_mwai/distributions-and-their-impact-on-data-science-50k4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Data science is built on the ability to extract meaningful insights from data. Before a data scientist can create predictive models or make business recommendations, they must first understand how the data is distributed. A &lt;strong&gt;distribution&lt;/strong&gt; describes how values are spread across a dataset, showing the frequency, pattern, and behavior of data points.&lt;/p&gt;

&lt;p&gt;Understanding distributions allows data scientists to identify trends, detect anomalies, select appropriate machine learning algorithms, and make reliable predictions.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is a Distribution?
&lt;/h1&gt;

&lt;p&gt;A distribution is the way in which data values are arranged and how often they occur. It answers questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are most values clustered around a central point?&lt;/li&gt;
&lt;li&gt;Is the data spread evenly or concentrated?&lt;/li&gt;
&lt;li&gt;Are there extreme values (outliers)?&lt;/li&gt;
&lt;li&gt;Does the data follow a predictable pattern?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, in a dataset containing customer spending, a distribution can reveal whether most customers spend similar amounts or whether a small number of customers contribute to a large portion of revenue.&lt;/p&gt;




&lt;h1&gt;
  
  
  Importance of Distributions in Data Science
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Understanding Data Behavior
&lt;/h2&gt;

&lt;p&gt;The first step in any data science project is &lt;strong&gt;Exploratory Data Analysis (EDA)&lt;/strong&gt;. By examining distributions through histograms, box plots, and density plots, data scientists can understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The center of the data (mean, median, mode)&lt;/li&gt;
&lt;li&gt;The spread of the data (variance and standard deviation)&lt;/li&gt;
&lt;li&gt;The presence of outliers&lt;/li&gt;
&lt;li&gt;The shape of the data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This understanding helps determine the best approach for further analysis.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Detecting Outliers and Data Quality Issues
&lt;/h2&gt;

&lt;p&gt;Distributions help identify unusual observations that may represent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data entry errors&lt;/li&gt;
&lt;li&gt;Fraudulent transactions&lt;/li&gt;
&lt;li&gt;Rare events&lt;/li&gt;
&lt;li&gt;Significant business opportunities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, a sudden spike in a customer's purchasing behavior may indicate either a fraudulent transaction or a valuable customer who should receive special attention.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Choosing the Right Machine Learning Model
&lt;/h2&gt;

&lt;p&gt;Many machine learning algorithms make assumptions about the underlying distribution of data.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linear Regression often assumes that residual errors are normally distributed.&lt;/li&gt;
&lt;li&gt;Naive Bayes uses probability distributions to calculate the likelihood of different classes.&lt;/li&gt;
&lt;li&gt;Clustering algorithms can be influenced by how data points are spread.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding the distribution of your data helps improve model accuracy and reliability.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Data Transformation and Feature Engineering
&lt;/h2&gt;

&lt;p&gt;Real-world data is often messy and skewed. Data scientists may transform distributions using methods such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log transformation&lt;/li&gt;
&lt;li&gt;Square root transformation&lt;/li&gt;
&lt;li&gt;Standardization&lt;/li&gt;
&lt;li&gt;Normalization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These transformations can reduce skewness and make data more suitable for machine learning algorithms.&lt;/p&gt;




&lt;h1&gt;
  
  
  Common Types of Distributions in Data Science
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Normal Distribution
&lt;/h2&gt;

&lt;p&gt;The normal distribution, also known as the &lt;strong&gt;bell curve&lt;/strong&gt;, is one of the most important distributions in statistics.&lt;/p&gt;

&lt;p&gt;Characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symmetrical around the mean&lt;/li&gt;
&lt;li&gt;Mean, median, and mode are equal&lt;/li&gt;
&lt;li&gt;Most observations cluster near the center&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Human heights&lt;/li&gt;
&lt;li&gt;Measurement errors&lt;/li&gt;
&lt;li&gt;Standardized test scores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many statistical techniques and machine learning methods rely on the assumption of normality.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Uniform Distribution
&lt;/h2&gt;

&lt;p&gt;In a uniform distribution, every outcome has an equal probability of occurring.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rolling a fair die&lt;/li&gt;
&lt;li&gt;Random number generation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is commonly used in simulations and random sampling.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Binomial Distribution
&lt;/h2&gt;

&lt;p&gt;The binomial distribution models the number of successes in a fixed number of independent trials.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of customers who click an advertisement&lt;/li&gt;
&lt;li&gt;Number of successful sales calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is widely used in marketing analytics and A/B testing.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Poisson Distribution
&lt;/h2&gt;

&lt;p&gt;The Poisson distribution describes the number of events occurring within a fixed period of time or space.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of website visitors per minute&lt;/li&gt;
&lt;li&gt;Number of customer support requests per day&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is valuable for forecasting and resource planning.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Exponential Distribution
&lt;/h2&gt;

&lt;p&gt;The exponential distribution models the time between events.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Time until a customer makes a purchase&lt;/li&gt;
&lt;li&gt;Time until a machine fails&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is commonly used in reliability analysis and survival studies.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Role of Distributions in Real-World Data Science
&lt;/h1&gt;

&lt;p&gt;Distributions influence almost every stage of a data science workflow:&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Collection
&lt;/h3&gt;

&lt;p&gt;They help determine whether collected data accurately represents a population.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Cleaning
&lt;/h3&gt;

&lt;p&gt;They reveal missing values, unusual patterns, and outliers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exploratory Data Analysis
&lt;/h3&gt;

&lt;p&gt;They provide a deeper understanding of relationships and trends.&lt;/p&gt;

&lt;h3&gt;
  
  
  Machine Learning
&lt;/h3&gt;

&lt;p&gt;They help in feature selection, transformation, and model evaluation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision-Making
&lt;/h3&gt;

&lt;p&gt;They allow businesses to estimate risk, predict outcomes, and plan for the future.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Distributions are a fundamental concept in data science because they describe the underlying behavior of data. A skilled data scientist does not simply look at numbers; they analyze how those numbers are distributed to uncover patterns, detect problems, and build accurate predictive models.&lt;/p&gt;

&lt;p&gt;From understanding customer behavior and forecasting sales to detecting fraud and developing artificial intelligence systems, distributions play a critical role in transforming raw data into valuable insights.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>data</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Pandas for Data Cleaning in Data Science Introduction</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Mon, 15 Jun 2026 05:05:37 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/pandas-for-data-cleaning-in-data-scienceintroduction-bnf</link>
      <guid>https://dev.to/samuel_mwai/pandas-for-data-cleaning-in-data-scienceintroduction-bnf</guid>
      <description>&lt;p&gt;In the field of data science and analytics, raw data is rarely perfect. Real-world datasets often contain missing values, duplicate records, incorrect formats, inconsistent text, and outliers that can affect the accuracy of analysis and machine learning models. Data cleaning is the process of detecting, correcting, and preparing raw data so that it becomes reliable and ready for analysis.&lt;/p&gt;

&lt;p&gt;One of the most powerful tools for data cleaning in Python is Pandas. Pandas is an open-source Python library that provides easy-to-use data structures and functions for manipulating and analyzing structured data. With its DataFrame and Series objects, Pandas allows data professionals to efficiently clean datasets of any size.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Loading Data into Pandas&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before cleaning data, the first step is importing it into a Pandas DataFrame.&lt;/p&gt;

&lt;p&gt;import pandas as pd&lt;/p&gt;

&lt;p&gt;df = pd.read_csv("sales_data.csv")&lt;/p&gt;

&lt;p&gt;To inspect the data:&lt;/p&gt;

&lt;p&gt;df.head()       # Displays first 5 rows&lt;br&gt;
df.tail()       # Displays last 5 rows&lt;br&gt;
df.info()       # Data types and missing values&lt;br&gt;
df.describe()   # Statistical summary&lt;br&gt;
df.shape        # Number of rows and columns&lt;/p&gt;

&lt;p&gt;Understanding the structure of the dataset helps identify potential data quality issues.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Handling Missing Values&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Missing data is one of the most common problems in datasets.&lt;/p&gt;

&lt;p&gt;Detecting Missing Values&lt;br&gt;
df.isnull()&lt;/p&gt;

&lt;p&gt;Count missing values in each column:&lt;/p&gt;

&lt;p&gt;df.isnull().sum()&lt;br&gt;
Removing Missing Values&lt;/p&gt;

&lt;p&gt;Remove rows with missing data:&lt;/p&gt;

&lt;p&gt;df.dropna()&lt;/p&gt;

&lt;p&gt;Remove columns containing missing values:&lt;/p&gt;

&lt;p&gt;df.dropna(axis=1)&lt;br&gt;
Filling Missing Values&lt;/p&gt;

&lt;p&gt;Replace missing values with a specific value:&lt;/p&gt;

&lt;p&gt;df.fillna(0)&lt;/p&gt;

&lt;p&gt;Fill numerical data using the mean:&lt;/p&gt;

&lt;p&gt;df["Age"] = df["Age"].fillna(df["Age"].mean())&lt;/p&gt;

&lt;p&gt;Fill categorical data using the mode:&lt;/p&gt;

&lt;p&gt;df["Country"] = df["Country"].fillna(df["Country"].mode()[0])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Removing Duplicate Data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Duplicate records can lead to inaccurate analysis.&lt;/p&gt;

&lt;p&gt;Identifying Duplicates&lt;br&gt;
df.duplicated()&lt;/p&gt;

&lt;p&gt;Count duplicate rows:&lt;/p&gt;

&lt;p&gt;df.duplicated().sum()&lt;br&gt;
Removing Duplicates&lt;br&gt;
df.drop_duplicates()&lt;/p&gt;

&lt;p&gt;Remove duplicates based on specific columns:&lt;/p&gt;

&lt;p&gt;df.drop_duplicates(subset=["Email"])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Correcting Data Types&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Incorrect data types can cause errors during analysis.&lt;/p&gt;

&lt;p&gt;Check data types:&lt;/p&gt;

&lt;p&gt;df.dtypes&lt;br&gt;
Converting Data Types&lt;/p&gt;

&lt;p&gt;Convert a column to an integer:&lt;/p&gt;

&lt;p&gt;df["Quantity"] = df["Quantity"].astype(int)&lt;/p&gt;

&lt;p&gt;Convert a column to a datetime format:&lt;/p&gt;

&lt;p&gt;df["Date"] = pd.to_datetime(df["Date"])&lt;/p&gt;

&lt;p&gt;Convert text to a numeric type:&lt;/p&gt;

&lt;p&gt;df["Price"] = pd.to_numeric(df["Price"])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cleaning Text Data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Text data often contains unnecessary spaces, inconsistent capitalization, or formatting problems.&lt;/p&gt;

&lt;p&gt;Removing Extra Spaces&lt;br&gt;
df["Name"] = df["Name"].str.strip()&lt;br&gt;
Changing Letter Case&lt;/p&gt;

&lt;p&gt;Convert to lowercase:&lt;/p&gt;

&lt;p&gt;df["City"] = df["City"].str.lower()&lt;/p&gt;

&lt;p&gt;Convert to uppercase:&lt;/p&gt;

&lt;p&gt;df["Country"] = df["Country"].str.upper()&lt;/p&gt;

&lt;p&gt;Convert to title case:&lt;/p&gt;

&lt;p&gt;df["Name"] = df["Name"].str.title()&lt;br&gt;
Replacing Incorrect Values&lt;br&gt;
df["Gender"] = df["Gender"].replace({&lt;br&gt;
    "M": "Male",&lt;br&gt;
    "F": "Female"&lt;br&gt;
})&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Renaming Columns&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Column names may be unclear or inconsistent.&lt;/p&gt;

&lt;p&gt;Rename a single column:&lt;/p&gt;

&lt;p&gt;df.rename(columns={"Cust_Name": "Customer_Name"})&lt;/p&gt;

&lt;p&gt;Rename all columns:&lt;/p&gt;

&lt;p&gt;df.columns = [&lt;br&gt;
    "id",&lt;br&gt;
    "name",&lt;br&gt;
    "age",&lt;br&gt;
    "city"&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;Standardize column names:&lt;/p&gt;

&lt;p&gt;df.columns = (&lt;br&gt;
    df.columns&lt;br&gt;
    .str.strip()&lt;br&gt;
    .str.lower()&lt;br&gt;
    .str.replace(" ", "_")&lt;br&gt;
)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Filtering Incorrect Data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sometimes datasets contain impossible or invalid values.&lt;/p&gt;

&lt;p&gt;Example: Remove customers with negative ages.&lt;/p&gt;

&lt;p&gt;df = df[df["Age"] &amp;gt;= 0]&lt;/p&gt;

&lt;p&gt;Remove unrealistic values:&lt;/p&gt;

&lt;p&gt;df = df[df["Salary"] &amp;lt;= 500000]&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detecting and Handling Outliers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Outliers are unusual values that significantly differ from the rest of the data.&lt;/p&gt;

&lt;p&gt;Using the Interquartile Range (IQR) method:&lt;/p&gt;

&lt;p&gt;Q1 = df["Salary"].quantile(0.25)&lt;br&gt;
Q3 = df["Salary"].quantile(0.75)&lt;/p&gt;

&lt;p&gt;IQR = Q3 - Q1&lt;/p&gt;

&lt;p&gt;lower = Q1 - 1.5 * IQR&lt;br&gt;
upper = Q3 + 1.5 * IQR&lt;/p&gt;

&lt;p&gt;df = df[&lt;br&gt;
    (df["Salary"] &amp;gt;= lower) &amp;amp;&lt;br&gt;
    (df["Salary"] &amp;lt;= upper)&lt;br&gt;
]&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Working with Dates&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dates often require cleaning and formatting.&lt;/p&gt;

&lt;p&gt;Convert strings to dates:&lt;/p&gt;

&lt;p&gt;df["Order_Date"] = pd.to_datetime(df["Order_Date"])&lt;/p&gt;

&lt;p&gt;Extract useful information:&lt;/p&gt;

&lt;p&gt;df["Year"] = df["Order_Date"].dt.year&lt;br&gt;
df["Month"] = df["Order_Date"].dt.month&lt;br&gt;
df["Day"] = df["Order_Date"].dt.day&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Handling Inconsistent Categories&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Categories may have different spellings representing the same value.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Before cleaning:&lt;/p&gt;

&lt;p&gt;USA&lt;br&gt;
U.S.A&lt;br&gt;
United States&lt;br&gt;
us&lt;/p&gt;

&lt;p&gt;Standardize them:&lt;/p&gt;

&lt;p&gt;df["Country"] = df["Country"].replace({&lt;br&gt;
    "U.S.A": "USA",&lt;br&gt;
    "United States": "USA",&lt;br&gt;
    "us": "USA"&lt;br&gt;
})&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finding Unique Values&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Checking unique values helps identify inconsistencies.&lt;/p&gt;

&lt;p&gt;View unique entries:&lt;/p&gt;

&lt;p&gt;df["Country"].unique()&lt;/p&gt;

&lt;p&gt;Count each category:&lt;/p&gt;

&lt;p&gt;df["Country"].value_counts()&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Saving the Cleaned Dataset&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After cleaning, save the dataset for future analysis.&lt;/p&gt;

&lt;p&gt;Save as CSV:&lt;/p&gt;

&lt;p&gt;df.to_csv("cleaned_data.csv", index=False)&lt;/p&gt;

&lt;p&gt;Save as Excel:&lt;/p&gt;

&lt;p&gt;df.to_excel("cleaned_data.xlsx", index=False)&lt;br&gt;
Best Practices for Data Cleaning with Pandas&lt;br&gt;
Always create a copy of the original dataset before cleaning.&lt;br&gt;
Explore the dataset using head(), info(), and describe().&lt;br&gt;
Handle missing values based on the context of the problem.&lt;br&gt;
Maintain consistent naming conventions.&lt;br&gt;
Validate data after every cleaning step.&lt;br&gt;
Document all transformations to ensure reproducibility.&lt;br&gt;
Use automated cleaning pipelines for large datasets.&lt;br&gt;
Conclusion&lt;/p&gt;

&lt;p&gt;Pandas is an essential library for data cleaning in Python and is widely used by data analysts, data scientists, and machine learning engineers. It provides powerful tools for identifying missing values, removing duplicates, correcting data types, standardizing text, handling outliers, and transforming datasets into a usable format.&lt;/p&gt;

&lt;p&gt;Effective data cleaning improves the quality of insights, reduces errors in analysis, and creates a strong foundation for advanced tasks such as data visualization, statistical analysis, and machine learning. Mastering Pandas data cleaning techniques is therefore a fundamental skill for anyone pursuing a career in data science and analytics.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>PYTHON IN DATA ANALYSIS</title>
      <dc:creator>Samuel Mwai</dc:creator>
      <pubDate>Thu, 07 May 2026 17:44:04 +0000</pubDate>
      <link>https://dev.to/samuel_mwai/python-in-data-analysis-25bk</link>
      <guid>https://dev.to/samuel_mwai/python-in-data-analysis-25bk</guid>
      <description>&lt;h1&gt;
  
  
  Introduction to Python for Data Analytics
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is Data Analytics?
&lt;/h2&gt;

&lt;p&gt;Data analytics is the process of collecting, cleaning, analyzing, and interpreting data to uncover meaningful insights and support decision-making. In today’s data-driven world, organizations rely on analytics to improve performance, understand customers, and predict future trends.&lt;/p&gt;

&lt;p&gt;Python has emerged as one of the most popular programming languages for data analytics due to its simplicity, flexibility, and powerful ecosystem.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use Python for Data Analytics?
&lt;/h2&gt;

&lt;p&gt;Python is widely used in data analytics for several reasons:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Easy to Learn and Read
&lt;/h3&gt;

&lt;p&gt;Python has a clean and simple syntax that resembles plain English. This makes it beginner-friendly and ideal for analysts who may not come from a programming background.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Powerful Libraries
&lt;/h3&gt;

&lt;p&gt;Python offers a rich set of libraries specifically designed for data analysis:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pandas&lt;/strong&gt; – for data manipulation and analysis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NumPy&lt;/strong&gt; – for numerical computations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Matplotlib &amp;amp; Seaborn&lt;/strong&gt; – for data visualization&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SciPy&lt;/strong&gt; – for scientific computing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These libraries allow you to perform complex operations with minimal code.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Strong Community Support
&lt;/h3&gt;

&lt;p&gt;Python has a large and active community. This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plenty of tutorials and documentation&lt;/li&gt;
&lt;li&gt;Open-source tools and libraries&lt;/li&gt;
&lt;li&gt;Quick help when you run into issues&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Versatility
&lt;/h3&gt;

&lt;p&gt;Python is not limited to data analytics. It can also be used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web development&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;li&gt;Machine learning&lt;/li&gt;
&lt;li&gt;Artificial intelligence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes it a valuable long-term skill.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Steps in Data Analytics Using Python
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Data Collection
&lt;/h3&gt;

&lt;p&gt;Data can come from various sources such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Databases (SQL)&lt;/li&gt;
&lt;li&gt;CSV/Excel files&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;Web scraping&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python makes it easy to import data using libraries like Pandas.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Data Cleaning
&lt;/h3&gt;

&lt;p&gt;Raw data is often messy. Cleaning involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handling missing values&lt;/li&gt;
&lt;li&gt;Removing duplicates&lt;/li&gt;
&lt;li&gt;Fixing data types&lt;/li&gt;
&lt;li&gt;Standardizing formats&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drop_duplicates&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_numeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;coerce&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. Data Exploration
&lt;/h3&gt;

&lt;p&gt;This step helps you understand your data using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Summary statistics&lt;/li&gt;
&lt;li&gt;Data distributions&lt;/li&gt;
&lt;li&gt;Relationships between variables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4. Data Visualization
&lt;/h3&gt;

&lt;p&gt;Visualization helps communicate insights effectively.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;hist&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  5. Data Analysis and Insights
&lt;/h3&gt;

&lt;p&gt;This is where you answer business questions, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What trends exist in the data?&lt;/li&gt;
&lt;li&gt;Which factors influence outcomes?&lt;/li&gt;
&lt;li&gt;What patterns can we identify?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupby&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;department&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;salary&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Python in Jupyter Notebooks
&lt;/h2&gt;

&lt;p&gt;Jupyter Notebook is a popular environment for data analytics because it allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write and execute code&lt;/li&gt;
&lt;li&gt;Visualize data inline&lt;/li&gt;
&lt;li&gt;Add explanations using text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s especially useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exploratory analysis&lt;/li&gt;
&lt;li&gt;Reporting&lt;/li&gt;
&lt;li&gt;Learning and experimentation&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real-World Applications
&lt;/h2&gt;

&lt;p&gt;Python is used in many industries for data analytics, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Finance&lt;/strong&gt; – risk analysis, trading strategies&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Healthcare&lt;/strong&gt; – patient data analysis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Marketing&lt;/strong&gt; – customer segmentation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;E-commerce&lt;/strong&gt; – recommendation systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Advantages of Python for Data Analysts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fast development and prototyping&lt;/li&gt;
&lt;li&gt;Integration with databases (SQL)&lt;/li&gt;
&lt;li&gt;Strong visualization capabilities&lt;/li&gt;
&lt;li&gt;Scalable for large datasets&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Python is a powerful and accessible tool for data analytics. Its simplicity, combined with a rich ecosystem of libraries, makes it an excellent choice for beginners and professionals alike.&lt;/p&gt;

&lt;p&gt;By mastering Python, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clean and analyze data efficiently&lt;/li&gt;
&lt;li&gt;Build meaningful visualizations&lt;/li&gt;
&lt;li&gt;Generate actionable insights&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're just starting out or advancing your analytics skills, Python provides the foundation you need to succeed in the world of data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;To continue learning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Practice with real datasets&lt;/li&gt;
&lt;li&gt;Build small analytics projects&lt;/li&gt;
&lt;li&gt;Learn advanced tools like machine learning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best way to learn Python for data analytics is by doing.&lt;/p&gt;




</description>
      <category>analytics</category>
      <category>beginners</category>
      <category>datascience</category>
      <category>python</category>
    </item>
  </channel>
</rss>
