How can I dynamically distinguish between categorical data and numerical data? I know someone who is working on a project that involves ingesting files of data without regard to the columns or data types. The task is to take a file with any number of columns and various data types and output summary statistics on the numerical data.

However, he is unsure of how to go about dynamically assigning data types for certain number-based data. For example:

    CITY
    Albuquerque
    Boston
    Chicago


This is obviously not numerical data and will be stored as text. However,

    ZIP
    80221
    60653
    25525


are not clearly marked as categorical. His software would assign the ZIP code as numerical and output summary statistics for it, which does not make sense for that sort of data.



A couple ideas we had were:


If a column is all integers, label it as categorical. This clearly wouldn't work, but it was an idea.
If a column has fewer than n unique values and is numeric, label it categorical. This might be closer, but there could still be issues with numerical data falling through.
Maintain a list of common numeric data that should actually be categorical and compare the column headers to this list for matches. For example, anything with "ZIP" in it would be categorical.




My gut tells me that there is no way to accurately assign numeric data as categorical or numerical, but was hoping for a suggestion. Any insight you have is greatly appreciated.
I'm not aware of a foolproof way to do this. Here's one idea off the top of my head:


Treat values as categorical by default.
Check for various attributes of the data that would imply it is actually continuous. Weight these attributes based on how likely they are to correlate with continuous data. Here are some possible examples:


Values are integers: +.7
Values are floats: +.8
Values are normally distributed: +.3
Values contain a relatively small number of unique values: +.3
Values aren't all the same number of characters: +.1
Values don't contain leading zeros: +.1

Treat any columns that sum to greater than 1 as being numerical. Adjust the factors and weights based on testing against different data sets to suit your needs. You could even build and train a separate machine learning algorithm just to do this.