Finding categorical variables

Categorical variables are variables that receive a limited number of values that describe a category. They can be of two types:

  • Ordinal – variables with two or more categories that can be ranked or ordered (e.g. “low”, “medium”, “high”)
  • Nominal – variables with two or more categories that do not have an intrinsic order (e.g. “men”, “women”)

In this exercise, you will find the categorical variables in the dataset. To do that, first of all, you will import the pandas library and read the CSV file called "turnover.csv". Then, after viewing the first 5 rows and learning (visually) that there are non-numeric values in the DataFrame, you will get some information about the types of variables that are available in the dataset.

This exercise is part of the course

HR Analytics: Predicting Employee Churn in Python

View Course

Exercise instructions

  • Import pandas (as pd) to read the data.
  • Read "turnover.csv" file and save it in a DataFrame called data.
  • Take a quick look to the first 5 rows of data.
  • Get some info()-rmation on the types of variables in data.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import pandas (as pd) to read the data
import ____ as pd

# Read "turnover.csv" and save it in a DataFrame called data
data = pd.____("turnover.csv")

# Take a quick look to the first 5 rows of data
print(data.____())

# Get some information on the types of variables in data
data.____()