first_digits analyzes leading-digit frequencies against an expected Benford distribution. It accepts a cleaned leading-digit variable and, with digs = 1, evaluates the first digit. section 12.4.1
Prepare the input and interpret the returned comparison:
- Extract the first character from each original value, inspect unusual results, retain digits 1 through 9, and convert the field to integers. section 12.4.1 section 12.4.3
- Call bf.first_digits(first_digit, digs = 1) to obtain a nine-row data frame containing digits, counts, observed percentages, and expected percentages. section 12.4.1
- Use the automatically displayed bar-line chart to compare observed frequencies with the perfect Benford distribution. section 12.4.1
Payment amounts
For utility payments, extract the first character from Amount, remove minus signs and zero values, convert the remaining digits to integers, and run bf.first_digits(). The resulting distribution has leading digits 1, 2, and 3 in 59% of records, compared with 60.2% under a perfect Benford distribution. section 12.4.3
>>> import benford as bf >>> bf_street_addresses = bf.first_digits(street_addresses.first_digit, >>> digs = 1)
Run the compact benford-library call after creating and validating the first_digit field. section 12.4.1
