Skip to content
Project: Examining the History of Lego Sets
Lego is a household name across the world, supported by a diverse toy line, hit movies, and a series of successful video games. In this project, we are going to explore a key development in the history of Lego: the introduction of licensed sets such as Star Wars, Super Heroes, and Harry Potter.
The introduction of its first licensed series, Star Wars, was a hit that sparked a series of collaborations with more themed sets. The partnerships team has asked you to perform an analysis of this success, and before diving into the analysis, they have suggested reading the descriptions of the two datasets to use, reported below.
The Data
You have been provided with two datasets to use. A summary and preview are provided below.
lego_sets.csv
Column | Description |
---|---|
"set_num" | A code that is unique to each set in the dataset. This column is critical, and a missing value indicates the set is a duplicate or invalid! |
"name" | The name of the set. |
"year" | The date the set was released. |
"num_parts" | The number of parts contained in the set. This column is not central to our analyses, so missing values are acceptable. |
"theme_name" | The name of the sub-theme of the set. |
"parent_theme" | The name of the parent theme the set belongs to. Matches the name column of the parent_themes csv file. |
parent_themes.csv
Column | Description |
---|---|
"id" | A code that is unique to every theme. |
"name" | The name of the parent theme. |
"is_licensed" | A Boolean column specifying whether the theme is a licensed theme. |
# Import pandas, read and inspect the datasets
import pandas as pd
# Load Data
lego_sets = pd.read_csv('data/lego_sets.csv')
parent_themes = pd.read_csv('data/parent_themes.csv')
# Groupby parent theme and count
is_licensed = parent_themes[parent_themes['is_licensed']==True]
name_list = list(is_licensed['name'])
df = lego_sets[lego_sets['parent_theme'].isin(name_list)]
df['parent_theme'].value_counts(normalize=True)
the_force = 46
#
star_wars_by_year = lego_sets[lego_sets['parent_theme']=='Star Wars'].groupby(by='year',as_index=True).agg({'name':'count'})
star_wars_by_year['name'].sort_values(ascending=False).index[0]
new_era = 2016