Skip to content

A common problem when creating models to generate business value from data is that the datasets can be so large that it can take days for the model to generate predictions. Ensuring that your dataset is stored as efficiently as possible is crucial for allowing these models to run on a more reasonable timescale without having to reduce the size of the dataset.

You've been hired by a major online data science training provider called Training Data Ltd. to clean up one of their largest customer datasets. This dataset will eventually be used to predict whether their students are looking for a new job or not, information that they will then use to direct them to prospective recruiters.

You've been given access to customer_train.csv, which is a subset of their entire customer dataset, so you can create a proof-of-concept of a much more efficient storage solution. The dataset contains anonymized student information, and whether they were looking for a new job or not during training:

ColumnDescription
student_idA unique ID for each student.
cityA code for the city the student lives in.
city_development_indexA scaled development index for the city.
genderThe student's gender.
relevant_experienceAn indicator of the student's work relevant experience.
enrolled_universityThe type of university course enrolled in (if any).
education_levelThe student's education level.
major_disciplineThe educational discipline of the student.
experienceThe student's total work experience (in years).
company_sizeThe number of employees at the student's current employer.
company_typeThe type of company employing the student.
last_new_jobThe number of years between the student's current and previous jobs.
training_hoursThe number of hours of training completed.
job_changeAn indicator of whether the student is looking for a new job (1) or not (0).
# Import necessary libraries
import pandas as pd

# Load the dataset
ds_jobs = pd.read_csv("customer_train.csv")

# View the dataset
ds_jobs.head()

Requirements:

  • Columns containing categories with only two factors must be stored as Booleans (bool).
  • Columns containing integers only must be stored as 32-bit integers (int32).
  • Columns containing floats must be stored as 16-bit floats (float16).
  • Columns containing nominal categorical data must be stored as the category data type.
  • Columns containing ordinal categorical data must be stored as ordered categories, and not mapped to numerical values, with an order that reflects the natural order of the column.
  • The DataFrame should be filtered to only contain students with 10 or more years of experience at companies with at least 1000 employees, as their recruiter base is suited to more experienced professionals at enterprise companies.
# Creating a copy
ds_jobs_copy = ds_jobs.copy()
ds_jobs_copy.info()
# EDA to find out which categories have to be converted into booleans, nominal and ordinal categorical data
ds_jobs_copy.columns
for col in ds_jobs_copy.columns:
    print(ds_jobs_copy[col].value_counts())
    print('\n')

relevant_experience and job_change only has 2 unique values. store as Booleans

# Storing relevant_experience and job_change as booleans
# Create a dictionairy of dictionaries 
boolean_data = {
    'relevant_experience' : { 'Has relevant experience': True, 'No relevant experience': False},
    'job_change' : {0.0:False, 1.0:True}
}
# Map the boolean_data to the relevant columns
ds_jobs_copy['relevant_experience']=ds_jobs_copy['relevant_experience'].map(boolean_data).astype('bool')
ds_jobs_copy['job_change']=ds_jobs_copy['job_change'].map(boolean_data).astype('bool')

student_id and training_hours only has integers. store as int32

# Converting numerical data with only integers (int 64 to int 32)
ds_jobs_copy['student_id'] = ds_jobs_copy['student_id'].astype('int32')
ds_jobs_copy['training_hours'] = ds_jobs_copy['training_hours'].astype('int32')

city_development_index is the only column with float datatype. store as float16

# Converting numerical data with decimals (float 64 to int 32)
ds_jobs_copy['city_development_index'] = ds_jobs_copy['city_development_index'].astype('float16')

major_discipline and city are nominal categories. store as category