Skip to main content

benfordslaw is to test if an empirical (observed) distribution differs significantly from a theoretical (expected, Benfords) distribution.

Project description


Python PyPI Version License Downloads Donate Bitcoin

  • benfordslaw is Python package to test if an empirical (observed) distribution differs significantly from a theoretical (expected, Benfords) distribution. The law states that in many naturally occurring collections of numbers, the leading significant digit is likely to be small. This method can be used if you want to test whether your set of numbers may be artificial (or manupilated). If a certain set of values follows Benford's Law then model's for the corresponding predicted values should also follow Benford's Law. Normal data (Unmanipulated) does trend with Benford's Law, whereas Manipulated or fraudulent data does not.

  • Assumptions of the data:

    1. The numbers need to be random and not assigned, with no imposed minimums or maximums.
    2. The numbers should cover several orders of magnitude
    3. Dataset should preferably cover at least 1000 samples. Though Benford’s law has been shown to hold true for datasets containing as few as 50 numbers.



  • Install benfordslaw from PyPI (recommended). benfordslaw is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.
  • It is distributed under the MIT license.


pip install -r requirements

Quick Start

pip install benfordslaw
  • Alternatively, install benfordslaw from the GitHub source:
git clone
cd benfordslaw
python install

Import benfordslaw package

import benfordslaw as bl

# Load elections example
df = bl.import_example()

# Extract election information.
X = df['votes'].loc[df['candidate']=='Donald Trump'].values

# Print
# array([ 5387, 23618,  1710, ...,    16,    21,     0], dtype=int64)

# Make fit
out =

# Plot
bl.plot(out, title='Donald Trump')


Please cite benfordslaw in your publications if this is useful for your research. Here is an example BibTeX entry:

  author={Erdogan Taskesen},




  • Contributions are welcome.


See LICENSE for details.


  • This work is created and maintained in my free time. Contributions of any kind are very appreciated. Sponsering is also possible.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for benfordslaw, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size benfordslaw-0.1.2-py3-none-any.whl (7.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size benfordslaw-0.1.2.tar.gz (6.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page