From an exploratory data analysis perspective, measures of location address a fundamental question: in what region of values does the observed phenomenon tend to concentrate?. In practical terms, this allows us to identify typical values, compare distributions, and begin interpreting the general behavior of the system before moving on to measures of dispersion, shape, or segmentation.
The dataset includes numerical variables such as Item_Weight, Item_Visibility, Item_MRP, and Item_Outlet_Sales, along with categorical variables associated with product type, establishment, and outlet location. For this initial analysis, we will focus on the univariate behavior of numerical variables using measures such as the mean, median, mode, and selected quantiles.
Environment Setup
We will work with the following BigMart dataset. For this section, we will use Python along with pandas, numpy, plotly, and matplotlib.
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltplt.rcParams["figure.figsize"] = (8, 4.5)plt.rcParams["axes.grid"] =TrueDATA_PATH ="../../data/bigmart_sales.csv"df = pd.read_csv(DATA_PATH)df.head()
Item_Identifier
Item_Weight
Item_Fat_Content
Item_Visibility
Item_Type
Item_MRP
Outlet_Identifier
Outlet_Establishment_Year
Outlet_Size
Outlet_Location_Type
Outlet_Type
Item_Outlet_Sales
0
FDA15
9.30
Low Fat
0.016047
Dairy
249.8092
OUT049
1999
Medium
Tier 1
Supermarket Type1
3735.1380
1
DRC01
5.92
Regular
0.019278
Soft Drinks
48.2692
OUT018
2009
Medium
Tier 3
Supermarket Type2
443.4228
2
FDN15
17.50
Low Fat
0.016760
Meat
141.6180
OUT049
1999
Medium
Tier 1
Supermarket Type1
2097.2700
3
FDX07
19.20
Regular
0.000000
Fruits and Vegetables
182.0950
OUT010
1998
NaN
Tier 3
Grocery Store
732.3800
4
NCD19
8.93
Low Fat
0.000000
Household
53.8614
OUT013
1987
High
Tier 3
Supermarket Type1
994.7052
Initial Inspection
Before calculating measures of location, it is good practice to identify available variable types and confirm which numerical columns will be analyzed.
At this stage, it is worth highlighting that not all numerical variables carry the same meaning. For instance, Item_MRP represents the maximum retail price of a product, while Item_Outlet_Sales corresponds to total sales of a product at a specific outlet. The interpretation of the “center” of each variable therefore depends on the economic context of the measurement.
Variable Selection for Location Analysis
For this stage, we will work with a subset of especially interpretable numerical variables:
Item_Weight
Item_Visibility
Item_MRP
Item_Outlet_Sales
We will create a new DataFrame with these columns to facilitate analysis, while also identifying the number of missing values present in them.
The presence of missing values in Item_Weight does not prevent us from initiating descriptive location analysis; however, dropping them without analyzing their origin can introduce bias into the results. Therefore, before computing descriptive statistics, it is necessary to examine the magnitude and potential pattern of missing data. Extracting a DataFrame with missing cases in Item_Weight gives:
While resolving missing data is not the primary objective of this section, maintaining a clear understanding of its impact is essential. To that end, three key questions guide our evaluation:
What percentage of data is missing for the variable?
This step assesses the magnitude of the issue. Calculating the proportion of missing values relative to total observations helps determine whether missingness represents a tiny fraction of the dataset or is large enough to impact representation.
print(f"Percentage of missing values in Item_Weight: {missing_report.loc['Item_Weight', 'missing_pct']:.2f}%")
Percentage of missing values in Item_Weight: 17.17%
In our case, the variable exhibits approximately 17% missing values, implying that nearly one-sixth of the observations lack information for this attribute. This proportion is non-negligible, so before excluding these records, we should check if missingness follows a systematic pattern and evaluate potential bias from dropping them.
Are there missingness patterns related to other variables?
Here we examine whether missing data occurs randomly or concentrates within specific groups (e.g., specific product categories, outlet types, or price ranges). Detecting non-random missingness patterns is critical because it signals potential bias.
Let us analyze the average missing rate for Item_Weight by product type and outlet type:
We observe that missing data in Item_Weight is primarily concentrated in two outlet types: Grocery Store and Supermarket Type1. This suggests that missingness is not entirely random, whereas the distribution across Item_Type is more balanced.
This missingness pattern may be tied to the nature of products sold at those outlets or specific data entry practices, meaning that dropping these cases without prior inspection could skew descriptive analysis.
import pandas as pdimport plotly.express as px# Missing proportion of Item_Weight by Outlet_Typemissing_outlet = ( df['Item_Weight'] .isna() .groupby(df['Outlet_Type']) .mean() .mul(100) .reset_index(name='pct_missing') .sort_values('pct_missing', ascending=False))fig = px.bar( missing_outlet, x='Outlet_Type', y='pct_missing', color='pct_missing', color_continuous_scale='Reds', text='pct_missing', labels={'Outlet_Type': 'Outlet Type','pct_missing': '% Missing in Item_Weight' }, title='Percentage of Missing Item_Weight Values by Outlet_Type')fig.update_traces( texttemplate='%{text:.1f}%', textposition='outside')fig.update_layout( yaxis_title='% Missing', xaxis_title='Outlet Type', coloraxis_colorbar_title='% Missing')fig.show()
What is the potential impact of removing missing cases on the analysis?
At this point, the key question is no longer just whether missing data exists, but whether removing it alters our overall interpretation. A natural step in EDA is comparing location measures before and after excluding incomplete records. If measures remain stable, omitting those records has limited impact; if they shift noticeably, missingness affects interpretation.
We will evaluate these associated location measures in the following sections.
Basic Measures of Location
As seen in the previous section, the most widely used measures at this stage are:
Median: the value splitting the lower and upper 50% of observations.
Mode: the most frequent value. For continuous variables, it is often more useful to reference the modal region observed in a histogram.
Quantiles: percentiles such as \(Q_{0.25}\), \(Q_{0.50}\), and \(Q_{0.75}\).
These can be computed quickly in pandas using methods mean(), median(), mode(), and quantile(). To facilitate comparative reading, it is helpful to build a summary table of these measures for each key numerical variable.
def mode_series(s): m = s.mode(dropna=True)iflen(m) ==0:return np.naniflen(m) ==1:return m.iloc[0]return m.iloc[:5].tolist()summary_loc = pd.DataFrame({"mean": df[vars_localizacion].mean(numeric_only=True),"median": df[vars_localizacion].median(numeric_only=True),"mode": [mode_series(df[c]) for c in vars_localizacion],"q25": df[vars_localizacion].quantile(0.25),"q75": df[vars_localizacion].quantile(0.75),"min": df[vars_localizacion].min(numeric_only=True),"max": df[vars_localizacion].max(numeric_only=True),})summary_loc
mean
median
mode
q25
q75
min
max
Item_Weight
12.857645
12.600000
12.1500
8.773750
16.850000
4.555
21.350000
Item_Visibility
0.066132
0.053931
0.0000
0.026989
0.094585
0.000
0.328391
Item_MRP
140.992782
143.012800
172.0422
93.826500
185.643700
31.290
266.888400
Item_Outlet_Sales
2181.288914
1794.331000
958.7520
834.247400
3101.296400
33.290
13086.964800
This table enables an initial comparative inspection. The relationship between mean and median is particularly informative. If both values are close, the distribution may be relatively symmetric or at least unaffected by extreme tails. If they diverge significantly, skewness should be anticipated in subsequent steps.
Statistical Interpretation of Mean and Median
In sales data, right-skewed distributions are common. This means most observations cluster at lower or moderate levels, but a long right tail of high values pulls the mean upward. In such cases, the mean becomes less representative of a “typical” value than the median.
We can illustrate this directly with histograms overlaid with vertical lines for both metrics.
from plotly.subplots import make_subplotsimport plotly.graph_objects as gofig = make_subplots( rows=2, cols=2, subplot_titles=vars_localizacion)for i, col inenumerate(vars_localizacion): s = df[col].dropna() row = i //2+1 col_pos = i %2+1 media = s.mean() mediana = s.median()# Histogram fig.add_trace( go.Histogram( x=s, nbinsx=30, name=col, showlegend=False ), row=row, col=col_pos )# Mean line fig.add_vline( x=media, line_dash="dash", line_width=2, annotation_text=f"Mean = {media:.2f}", annotation_position="top right", row=row, col=col_pos )# Median line fig.add_vline( x=mediana, line_dash="dot", line_width=2, annotation_text=f"Median = {mediana:.2f}", annotation_position="top left", row=row, col=col_pos ) fig.update_xaxes(title_text=col, row=row, col=col_pos) fig.update_yaxes(title_text="Frequency", row=row, col=col_pos)fig.update_layout( height=700, width=1000, bargap=0.05)fig.show()
Overlaying these vertical lines offers immediate interpretation. Specifically, if for Item_Outlet_Sales the mean falls noticeably to the right of the median, we conclude that sales are right-skewed and driven upward by high-volume outlier cases. Conversely, if for Item_MRP both measures are close, the pricing structure is more balanced and symmetric.
Quantiles and Expanded Inspection of the Center
When discussing location, summarizing a variable with a single value like mean or median is not always sufficient. Describing the central region containing the majority of observations is often more informative. For this purpose, quantiles are particularly valuable.
Specifically, the 25th, 50th, and 75th percentiles define the range containing the middle 50% of the data. This information answers richer questions than a simple “what is the average?”, such as:
Between what values does the central half of observations lie?
How far do high values extend beyond the center?
Does the median accurately reflect the distribution center, or does significant skewness exist?
The quantiles table expands our inspection of the center. While the mean summarizes location in one number, quantiles reveal how data spreads around that center. Thus, the 25th percentile marks the point below which 25% of observations fall, the median divides the distribution into two equal halves, and the 75th percentile marks the upper bound of the middle 50%.
To complement this analysis, boxplots provide a visual representation of median, quartiles, central spread, and potential outliers.
from plotly.subplots import make_subplotsimport plotly.graph_objects as gofig = make_subplots( rows=2, cols=2, subplot_titles=vars_localizacion)for i, var inenumerate(vars_localizacion): row = i //2+1 col = i %2+1 fig.add_trace( go.Box( y=df[var].dropna(), name=var, boxpoints="outliers", showlegend=False ), row=row, col=col )fig.update_layout( title="Boxplots of Selected Variables", height=700, width=900)fig.show()
From these plots, interpretation extends beyond a single “average” to focus on overall distribution structure. Specifically, boxplots show:
median location;
interquartile range (IQR) width;
distribution symmetry vs. skewness;
presence of outliers that might distort the mean.
Thus, quantiles and boxplots enrich location analysis by showcasing not just a numerical center, but the region where most data actually concentrates.
Impact of Removing Missing Values in Item_Weight
To assess whether dropping records with missing Item_Weight values introduces bias, we compare dataset behavior before and after filtering. The goal is to verify if sample reduction significantly alters location measures of key variables or overall data composition.
First, we create two subsets:
the original dataset;
the filtered dataset containing only records with complete Item_Weight entries.
The results demonstrate that dropping observations with missing Item_Weight produces minor changes in location measures across analyzed variables. While percentage differences slightly exceed 2% in a few cases (e.g., Item_Outlet_Sales and Item_Visibility), the magnitude of these shifts is insufficient to alter our overall interpretation of distribution centers. Therefore, within the context of this EDA, working with complete cases represents a reasonable decision carrying minimal risk of location bias.
Suggested Exercise
Build an initial Quarto dashboard version including:
a summary table with mean, median, and quantiles for selected numerical variables;
a histogram with mean and median vertical lines for Item_Outlet_Sales;
a bar chart displaying median sales by Outlet_Type;
a brief commentary comparing mean vs. median usage.