Data Science Data Types
Distinguish numerical amounts from category labels before calculating.
How it works
A column’s storage type and its meaning are separate. A kiosk identifier may contain digits without representing a quantity you should average. Counts, measured amounts, ordered categories and free text support different operations. Preserve units and permissible values alongside the dtype. Treat Boolean flags deliberately rather than assuming every integer-coded column is a continuous measurement.
Run the code
Try in playground opens the correct pandas editor and preloads the complete source. Choose Run to execute; loading does not execute it. The isolated browser runtime does not read personal PC files.
Local review: Python 3.12.14, NumPy 2.5.4, Pandas 3.0.6 and SciPy 1.18.0. Browser review: Pyodide 0.27.7, Python 3.12.7, NumPy 2.0.2, Pandas 2.2.3 and SciPy 1.14.1 in their respective editors. Save the download as data-types.py and run python data-types.py in your separate environment. Apache and MySQL are not needed. Environment setup.
Example
import pandas as pd
table = pd.DataFrame({"kiosk": ["K01", "K02"], "refills": [4, 7], "litres": [8.5, 13.0], "open": [True, False]})
assert table["kiosk"].dtype.kind in "OUT"
assert table["refills"].sum() == 11
assert table["open"].sum() == 1
print("Two identifiers; eleven refills; one open flag")
Expected result
Two identifiers; eleven refills; one open flag
The kiosk code stays textual even though its suffix is numeric. Summing refills has an interpretation; averaging K01 and K02 does not. Pandas string storage can change across releases, so the assertion accepts documented text-like dtype kinds rather than depending on a display label. Schema tests should focus on the intended analytical contract.
Technical references: NumPy, Pandas and SciPy. For evaluation design see the scikit-learn guide to leakage; these examples do not require scikit-learn.