Long-tailed data is everywhere. It’s super common: salaries, customer lifetime values, durations of failures. If your histogram shows a rapid hump that then slowly decreases toward the right (Chart 1 below), that’s your long tail. Whenever you see a long-tailed histogram, use my quick life-saving hack: redraw it on a logarithmic scale, and you will see miracles. Otherwise you risk completely misinterpreting the chart, like I did.
This long-tailed data has a hidden property: it is “lognormal”. Not always, but often. Lognormal data is tricky, because the features of the histogram remain invisible on a linear scale. Draw it the wrong way and you will misread it badly, not by a few percent but by orders of magnitude. In this story I show what happened to me in a real project: during quick exploratory data analysis (EDA), my estimate was off by a factor of ten thousand. What would prevent it? Plotting the histogram on a logarithmic scale.
If you run EDA on durations, costs or latencies, this is for you.
The story is a Jupyter notebook. If you are not interested in the code, skip the grey boxes and read the charts.
The problem with lognormal data
When your data is lognormal, it needs a logarithmic scale. To see why, let us generate a lognormal data set and draw it in a plain histogram (without logarithmic scale).
import pandas as pd, numpy as np
import matplotlib.pyplot as plt, seaborn as sns
import loghist # my small helper module, linked at the end
np.random.seed(2021)x = np.random.lognormal(mean=10.0, sigma=0.8, size=100000)
fig, ax = plt.subplots(1, 1, figsize=(12, 3))
ax.hist(x=x, bins=100, range=(0, 200000))
ax.axvline(x=11000, color='red', linestyle='dashed', label='where the eye puts it (mode)')
ax.axvline(x=x.mean(), color='black', linestyle='dashed', label='mean')
ax.legend(); plt.show()
The histogram is right-skewed: a spike on the left and a very long tail to the right. Many real data sets look like this. Salaries do. So do the lifetimes of help-desk incidents, which I worked with for years: most incidents are resolved quickly, but a minority lives long, and because those long lifetimes differ so much from each other, they do not form a second spike. They form the tail.
And here is the problem. What is the average value of this population? Inexperienced readers point at the peak, around 11,000. The real mean is about 30,000. The tail looks visually insignificant, so we intuitively discount it. This time we were “only” wrong by a factor of three. Now for a more radical example.
Now it gets interesting
Below I generate three populations of 10,000 points each and mix them into one set. I am doing this to recreate the characteristics of a real data set that I experienced in production. The data represents the duration of hardware failures, in minutes: 30,000 failures in total; each lasting a few seconds to a few years. We will plot those durations to see how long a typical failure lasts. First, let’s create the synthetic data.
df1 = pd.DataFrame({'data': np.random.lognormal(mean=3.0, sigma=1.3, size=10000), 'group': '1 short'})
df2 = pd.DataFrame({'data': np.random.lognormal(mean=8.0, sigma=1.2, size=10000), 'group': '2 medium'})
df3 = pd.DataFrame({'data': np.random.lognormal(mean=13.0, sigma=1.0, size=10000), 'group': '3 long'})
df = pd.concat([df1, df2, df3])
df['seconds'] = df.data * 60Let us look at it on a linear scale, in eight views spanning from one minute to one year. (The function hist8t is my small utility plotting just what you see below: the same histogram in eight resolutions, using matplotlib. For its definition, see the GitHub link, bottom of the story.)
loghist.hist8t(df, 'data', unit='minute')So, forget that you know how the data was generated. Focus on the charts and tell me what you see. When I saw the chart, I said: nothing special. A typical lognormal chart: a lot of short events, and a long tail toward the right.
So, how long does a failure last, on average? I would look at the second chart on the left (“range: 1 hour, bin: 1 minute”) and visually estimate what we saw earlier in Chart 1. Twenty or thirty minutes, I’d say.
Let us check:
df.data.mean()
>>> 251659.08Surprise. The mean is about 250,000 minutes: 175 days. Our estimate was wrong by a factor of roughly 10,000.
How could we be so wrong? Nothing happened except the choice of chart, which was misleading. Here is the same data on a logarithmic scale:
fig, ax = plt.subplots(1, 1, figsize=(12, 3.5))
loghist.lhist(axis=ax, df=df, field='seconds', xticks='time', markers=False)
ax.axvline(x=df.seconds.mean(), color='red', linestyle='dashed', label='mean')
ax.axvline(x=df.seconds.median(), color='black', linestyle='dashed', label='median')
ax.legend(); plt.show()
The data looks completely different. The population is trimodal: it consists of three distinct groups. In practical terms (remembering that the data represents hardware failures), it looks like there are three kinds of failures: ones that last around 20 minutes, ones that last around two days, and ones that last around ten months. On the linear charts, the second and third groups were practically invisible; only the logarithmic scale will show them. And the mean, far to the right, now makes sense: it is dragged there by the third group.
The loghist module
This is why, a few years back, I wrote loghist, a small Python utility module for drawing data with long tails. You saw its two main functions above: hist8t draws linear views at eight time scales, and lhist draws a histogram on a log axis, with time labels if you want. Both can also stack groups in different colors. Here are the three populations stacked, first on a linear scale, then on a log scale.
First, let’s draw the data on a linear scale:
loghist.hist8t_stacked(df, 'data', group_field='group', unit='minute')Now, the same data, log scale:
fig, ax = plt.subplots(1, 1, figsize=(12, 3.5))
loghist.lhist(axis=ax, df=df, field='seconds', group_field='group',
bin_density=8, xticks='time', markers=False)
plt.show()On the linear scale the data looks like uninteresting garbage. On the log scale it tells a clear story, and you can see where the three populations overlap.
Mean, median, or the wrong question
The mean is a poor summary of a skewed distribution; the median is more robust. More broadly, a population like this cannot be described by any single number, so “what is the average?” may be the wrong question.
The log scale helps here too. Look again at the black line on the log chart (Chart 3): the median, about two days, sits right where an untrained reader of that chart would put “the middle”. On a log scale, intuition and statistics agree again.
So which number should you report? Here are the candidate statistics for our 30,000 failures:
q = df.data.quantile([0.5, 0.9, 0.95, 0.99])
summary = pd.Series({'mean': df.data.mean(), 'median (p50)': q[0.5],
'p90': q[0.9], 'p95': q[0.95], 'p99': q[0.99]})
(summary / 60 / 24).round(1).rename('days')
>>>
mean 174.8
median (p50) 2.1
p90 533.3
p95 870.2
p99 2075.6Each answers a different question:
Median: what does a typical case look like? Two days.
90th, 95th or 99th percentile: how bad does it get for the unlucky few? This is the number for SLAs and capacity planning.
You can also focus on business measures, like the total cost of ownership of a process. Once you convert all those failures to dollars, the total bill will tell the true story.
Where you will meet this today
Help-desk tickets and hardware failures are where I first met this shape. Today it sits under some of the most expensive numbers in data architecture. Two examples out of many:
LLM latency and cost per request. Most calls are short. A few, such as long contexts, retries and agent loops that take many steps, are very long. Average latency hides the p99 that users actually complain about, and an average cost per call hides the handful of runs that dominate the bill.
Query run times and cloud bills. Data warehouse or Spark queries have the same long tail. A cost forecast built on the typical query will be wrong; the tail defines the invoice.
The lesson: if your data has a long right tail, plot it on a log scale before you summarize it, and choose the summary number by the question you need to answer.
The code
The loghist module is free to use and improve; it is illustrative rather than production code.
Revisited: first published on WordPress, 2021
This image, which I used as the story’s cover, shows the very old wine bottles photographed in the wine cellar of Cricova: the enormous underground labyrinth of 120 kilometers of tunnels full of wine, wine and more wine bottles. That’s near Chișinău, Moldova. Must-see.







I remember expecting normal distribution everywhere after studies... Then real world hit and skews are everywhere!
Thanks for sharing and definitely must have tactic in every data person's pocket
Very useful! (The most interesting metrics after all are skewed)