Data Types

Before analysing any dataset, it's important to understand what type of data each column represents, since that determines which statistical methods and visualisations are appropriate.

Qualitative (Categorical) Data

Describes qualities or categories rather than numbers - for example, city names, gender, or product colour. Qualitative data splits further into:

  • Nominal - categories with no natural order, such as "Red", "Blue", "Green".
  • Ordinal - categories with a meaningful order but no fixed numeric gap, such as "Low", "Medium", "High".

Quantitative (Numerical) Data

Represents measurable quantities. Quantitative data splits further into:

  • Interval - numeric data with meaningful gaps but no true zero, such as temperature in Celsius.
  • Ratio - numeric data with meaningful gaps and a true zero, such as height, weight, or income.

Discrete vs Continuous

Quantitative data can also be described as discrete (countable whole values, like the number of students in a class) or continuous (any value within a range, like a person's exact height).

import pandas as pd

df = pd.DataFrame({
    "City": ["Noida", "Delhi"],          # nominal
    "Rating": ["Good", "Excellent"],      # ordinal
    "TemperatureC": [28.5, 31.2],         # interval
    "Income": [45000, 62000]              # ratio
})
print(df.dtypes)
Identifying data type correctly matters practically too - for instance, calculating an "average" doesn't make sense for nominal data like city names, even though Pandas won't stop you from trying.

Coming Up Next

Next, you'll get introduced to Exploratory Data Analysis (EDA) as a formal step in the Data Science process.

Telling Pandas What Each Column Really Is

Pandas guesses types when it loads a file, and the guess is often wrong for data science purposes. Text columns arrive as object, ratings arrive as plain strings, and IDs arrive as numbers. Fixing this early makes later steps safer.

import pandas as pd

df = pd.read_csv("survey.csv")

# nominal: unordered categories
df["City"] = df["City"].astype("category")

# ordinal: categories with a defined order
levels = ["Poor", "Average", "Good", "Excellent"]
df["Rating"] = pd.Categorical(df["Rating"], categories=levels, ordered=True)

# identifiers that look numeric but are labels
df["PinCode"] = df["PinCode"].astype("string")

print(df.dtypes)
print(df[df["Rating"] >= "Good"])   # works because the order is known

With an ordered categorical, comparisons such as "Good or better" behave correctly, and sorting follows the business order instead of alphabetical order. Category columns also use less memory than repeated strings.

Matching Analysis Methods to Data Types

TypeSensible summaryGood chartAvoid
NominalCounts, mode, proportionsBar chartMean, median, line chart
OrdinalMedian, percentiles, counts per levelOrdered bar chartTreating gaps between levels as equal
IntervalMean, standard deviation, differencesHistogram, line chartRatios such as "twice as hot"
RatioMean, ratios, growth ratesHistogram, box plot, scatterNothing special; most methods apply

The same thinking applies to models. Nominal features usually need one-hot encoding, while ordinal features can be mapped to integers that keep their order.

df = pd.get_dummies(df, columns=["City"])     # nominal to 0/1 columns
df["RatingCode"] = df["Rating"].cat.codes      # ordinal to 0, 1, 2, 3

Tree-based models can often work with ordinal codes directly, while linear models may read them as evenly spaced numbers, so think about which assumption is acceptable.

A Quick Classification Exercise

Try labelling these columns from an e-commerce dataset before reading the answers:

  • Payment method (UPI, card, cash): nominal.
  • Delivery speed (standard, express, same-day): ordinal.
  • Order date: interval-like for differences in days; you can subtract dates but "double the date" means nothing.
  • Items in cart: ratio and discrete.
  • Order value: ratio and continuous.
  • Customer ID: nominal, even though it is stored as digits.

Common Type Traps

  • Averaging codes such as pin codes, phone numbers or product IDs.
  • Letting a single bad value like "N/A" turn a numeric column into text; use pd.to_numeric(col, errors="coerce") and then inspect the missing values.
  • Encoding ordinal levels alphabetically, which puts "Excellent" before "Poor".
  • Losing leading zeros when IDs are read as integers.
  • Forgetting that a 1 to 5 survey score is ordinal; a mean may be reported, but explain that it is an approximation.

Checklist before analysis: run df.dtypes, list each column's real type, convert categories and dates, and note which statistics are allowed for each column.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course